NullPointerException : println needs a message in android

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());

In the catch, use:

String err = (ex.getMessage()==null)?"SD Card failed":ex.getMessage();
Log.e("sdcard-err2:", err);

Passing null to the second argument of a Log logging function throws that error, regardless of the source.


Maybe there's simply no message attached in exception you're catching. Try ex.printStackTrace(); instead. Hope this helps.


Another way that can to use is with Log.getStackTraceString(e), example:

Log.e(TAG, Log.getStackTraceString(e));

You can read more about that in Android Documentation.


"println needs a megssage" was a very confusing message to receive (at least for me) when not using the println(...) method at all!!!

In my case and for that matter in all cases that generate this type of error there is a constellation you have to watch out for:

try{
...
}catch(..){
  // in here there is a reference to the Logger
}

Now the problem is that in your try{...} block you are using an uninitialized reference or some old instance that now points to null

Setup a break-point at the very beginning of your try block and debug your code step by step, you will find that at some point the code will try to access methods of some object that is null.

In this case I tend to blame your seek object !

Regards.