2013-05-06 75 views
0

我收到了一個我不明白的異常。從設備350,只有三個這樣的。下面是日誌本身:Android日誌java.lang.NullPointerException

java.lang.IllegalStateException: Could not execute method of the activity 
    at android.view.View$1.onClick(View.java:3724) 
    at android.view.View.performClick(View.java:4261) 
    at android.view.View$PerformClick.run(View.java:17356) 
    at android.os.Handler.handleCallback(Handler.java:615) 
    at android.os.Handler.dispatchMessage(Handler.java:92) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4921) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
    at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.reflect.InvocationTargetException 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at android.view.View$1.onClick(View.java:3719) 
     ... 11 more 
    Caused by: java.lang.NullPointerException 
    at com.ex.MainActivity.ParseQueryMap(MainActivity.java:397) 
    at com.ex.MainActivity.onClickParse(MainActivity.java:493) 
    ... 14 more 

這裏是我認爲的錯誤是來自:

public void onClickParse(View view) {   
    myMap.clear(); 
    ParseQueryMap(); 
} 

,並從數據庫(ParseQueryMap)查詢

public void ParseQueryMap() { 
    userLocation = new ParseGeoPoint(location.getLatitude(), location.getLongitude()); 
    ParseQuery query = new ParseQuery("MyObject"); 
    query.findInBackground(new FindCallback() { 
    public void done(List<ParseObject> myObject, ParseException e) { 
     if (e == null) { 
     for (int i = 0; i < myObject.size(); i++) { 
      commGet = myObject.get(i).getString("Comment"); 
      bugGet = myObject.get(i).getObjectId(); 
      geo1Dub = myObject.get(i).getParseGeoPoint("location").getLatitude(); 
      geo2Dub = myObject.get(i).getParseGeoPoint("location").getLongitude(); 
     } 
     } else { 
     Toast.makeText(MainActivity.this, "Error!", Toast.LENGTH_SHORT).show(); 
     } 
    } 
    }); 

有誰知道什麼導致這個錯誤?

+2

哪條線是397線?有一個參考是'null'。 – Santa 2013-05-06 19:04:03

+0

+1給聖誕老人的評論,因爲如果我們看到堆棧跟蹤中列出的是#397行,我們可以幫助你更好。 – user1445967 2013-05-06 19:07:14

+0

你是什麼意思「從設備350,只有三個這樣的」? – 2013-05-06 19:09:38

回答

0

通常會發生這種情況,當您的代碼假定它不會爲空時,對象引用爲空。找到它的最簡單方法之一:在IDE中的第397行設置一個調試斷點,以調試模式運行應用程序,然後對該行的每個名稱或表達式使用inspect/watch來查找具有null值的值。