Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
623 views
in Technique[技术] by (71.8m points)

NullPointerException : println needs a message in android

in my media player i play a song from sdcard. it shows error as NullPointerException : println needs a message e in android. i tried long time but i do not know the reason .please assist me.

code:

    try {
        mediaPlayer = new  MediaPlayer();
        mediaPlayer.setDataSource("/sdcard/t1.mp3");
        seek.setMax(mediaPlayer.getDuration());
        mediaPlayer.prepare();
        mediaPlayer.start();
        mediaPlayer.setOnCompletionListener(this);          
    }
    catch(Exception ex){
        Log.e("sdcard-err2:",ex.getMessage());  //  null pointer exception : println needs a message 
    }  

Log cat:

     05-16 19:27:54.491: ERROR/AndroidRuntime(6889): Caused by: java.lang.NullPointerException: println needs a message
     05-16 19:27:54.491: ERROR/AndroidRuntime(6889):     at android.util.Log.println(Native Method)
     05-16 19:27:54.491: ERROR/AndroidRuntime(6889):     at android.util.Log.e(Log.java:208)
     05-16 19:27:54.491: ERROR/AndroidRuntime(6889):     at com.seek.bar.media3.onCreate(media3.java:43)
     05-16 19:27:54.491: ERROR/AndroidRuntime(6889):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
     05-16 19:27:54.491: ERROR/AndroidRuntime(6889):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
     05-16 19:27:54.491: ERROR/AndroidRuntime(6889):     ... 11 more
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For anyone else that gets this, try replacing the lone method call or variable name with "" + varName.

For example,

Log.d("LOGCAT", getErrorMsg());

becomes

Log.d("LOGCAT", "" + getErrorMsg());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...