0

我遇到了一个我不明白的异常。从设备 350 开始,只有三个这样的。以下是日志本身:

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

有谁知道是什么导致了这个错误?

4

1 回答 1

0

通常,当对象引用在您的代码假定它不会为空的地方为空时,就会发生这种情况。找到它的最简单方法之一:在 IDE 中的第 397 行设置调试断点,在调试模式下运行应用程序,然后对该行中的每个名称或表达式使用检查/监视来找出值为 null 的内容。

于 2013-05-06T19:11:07.243 回答