本文介绍了显示java.lang.NullPointerException:需要的println消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到的errror:显示java.lang.NullPointerException:需要的println消息时使用该梅索德:
lst_info =新的HashMap<字符串,字符串>();
SystemDatabaseHandler分贝=新SystemDatabaseHandler(getApplicationContext());
lst_info = db.getLstInfo(SQL_ID);
SystemDatabaseHandler:
公开的HashMap<字符串,字符串> getLstInfo(INT ID){
HashMap的<字符串,字符串> lst_temp;
lst_temp =新的HashMap<字符串,字符串>(); 字符串selectQuery =SELECT * FROM dkr_lst_lst WHERE lst_id =+ ID;
SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);
如果(cursor.moveToFirst()){
做{
Log.d(SQL_ID,cursor.getString(0));
lst_temp.put(SQL_ID,cursor.getString(0));
}而(cursor.moveToNext());
}
cursor.close();
db.close();
返回lst_temp;
}
Log.d(SQL_ID,cursor.getString(0));返回我:
The Log Cat:
07-12 11:56:05.613: D/Database(13783): dbclose(): path = /data/data/de.bodprod.dkr/databases/dkr, handle = 0x4301a8
07-12 11:56:05.613: D/AndroidRuntime(13783): Shutting down VM
07-12 11:56:05.613: W/dalvikvm(13783): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
07-12 11:56:05.623: E/AndroidRuntime(13783): FATAL EXCEPTION: main
07-12 11:56:05.623: E/AndroidRuntime(13783): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.bodprod.dkr/de.bodprod.dkr.BosLstDetailMap}: java.lang.NullPointerException: println needs a message
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.os.Looper.loop(Looper.java:150)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.ActivityThread.main(ActivityThread.java:4385)
07-12 11:56:05.623: E/AndroidRuntime(13783): at java.lang.reflect.Method.invokeNative(Native Method)
07-12 11:56:05.623: E/AndroidRuntime(13783): at java.lang.reflect.Method.invoke(Method.java:507)
07-12 11:56:05.623: E/AndroidRuntime(13783): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
07-12 11:56:05.623: E/AndroidRuntime(13783): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
07-12 11:56:05.623: E/AndroidRuntime(13783): at dalvik.system.NativeStart.main(Native Method)
07-12 11:56:05.623: E/AndroidRuntime(13783): Caused by: java.lang.NullPointerException: println needs a message
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.util.Log.println_native(Native Method)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.util.Log.d(Log.java:137)
07-12 11:56:05.623: E/AndroidRuntime(13783): at de.bodprod.dkr.BosLstDetailMap.onCreate(BosLstDetailMap.java:43)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
07-12 11:56:05.623: E/AndroidRuntime(13783): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
07-12 11:56:05.623: E/AndroidRuntime(13783): ... 11 more
07-12 11:56:07.495: D/Process(13783): killProcess, pid=13783
解决方案
Maybe when you do
Log.d("sql_id", cursor.getString(0));
cursor.getString(0) return null, and then it crash.
Try to do :
if(cursor.getString(0) != null) {
Log.d("sql_id", cursor.getString(0));
}
Else show us de.bodprod.dkr.BosLstDetailMap.onCreate(BosLstDetailMap.java:43)
这篇关于显示java.lang.NullPointerException:需要的println消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!