web-dev-qa-db-ja.com

java.lang.NullPointerException:printlnにはメッセージが必要です

エラーが発生します:Java.lang.NullPointerException:printlnは、このメソッドを呼び出すときにメッセージが必要です。

lst_info = new HashMap<String, String>();
SystemDatabaseHandler db = new SystemDatabaseHandler(getApplicationContext());
lst_info = db.getLstInfo(sql_id);

SystemDatabaseHandler:

public HashMap<String , String> getLstInfo(int id){
    HashMap<String , String> lst_temp;
    lst_temp = new HashMap<String , String>();

    String selectQuery = "SELECT * FROM dkr_lst_lst WHERE lst_id = " + id;
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    if (cursor.moveToFirst()) {
        do {
            Log.d("sql_id", cursor.getString(0));
            lst_temp.put("sql_id", cursor.getString(0));
        }while (cursor.moveToNext());
    } 
    cursor.close();
    db.close();
    return lst_temp;
}

Log.d( "sql_id"、cursor.getString(0));戻り値:

07-12 11:56:05.603:D/sql_id(13783):1

ログキャット:

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
22
Laire

たぶんあなたが電話するとき

_Log.d("sql_id", cursor.getString(0)); 
_

cursor.getString(0)はnullを返し、その後クラッシュします。

試してください:

_if(cursor.getString(0) != null) {
    Log.d("sql_id", cursor.getString(0)); 
}
_

それ以外の場合は、de.bodprod.dkr.BosLstDetailMap.onCreate(BosLstDetailMap.Java:43)を表示します

36
NitroG42

として試してください:

Log.d("sql_id"," " + cursor.getString(0));

の代わりに

Log.d("sql_id", cursor.getString(0));

おそらく、Log.dの2番目のパラメーターを空またはnullで渡しているためです

12