我是 Android 开发和 SO 的新手,几个月前才开始。到目前为止,你们帮了大忙!我正在使用尽可能多的外部库。
我正在使用Volley和JSONObject向服务器发出 GET 请求。问题是
W/dalvikvm:threadid=1:线程以未捕获的异常退出(组=0x40a6c9d8)
被抛出,我在尝试使用响应中的对象时得到 NPE。
这在我使用 JSONObjectRequest 的其他时候不会发生,只是这个。我研究并发现了有关 AndroidManifest.xml 中应用程序标记中的 android:name 字段的信息。我不认为是这样。
我怀疑这是关于在不同的线程中提出请求,但为什么其他时间不会发生......?
好吧,我的 logcat 和代码如下。请帮我!!!
日志猫:
07-16 02:01:37.466 22635-22635/com.revmob.android.setup W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40a6c9d8)
07-16 02:01:37.476 22635-22635/com.revmob.android.setup E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.revmob.android.setup/com.pubmobile.ellow.Controller.Main.MatchFragment.MatchRequestActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1975)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4443)
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:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.pubmobile.ellow.Controller.Main.MatchFragment.MatchRequestActivity.onCreate(MatchRequestActivity.java:109)
at android.app.Activity.performCreate(Activity.java:4668)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1939)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4443)
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:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
我的代码: MatchRequestActivity.java
String url = Constants.URL_SERVER;
JsonObjectRequest getMatchRequest = new JsonObjectRequest(com.android.volley.Request.Method.GET, url, new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if(response != null) {
System.out.println(response);
} else{
System.out.println("null Response from getMatchRequest");
}
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("no Response from getMatchRequest");
}
});
RequestQueueManager.getInstance(this).addToRequestQueue(getMatchRequest);
我现在拥有的:
虽然我的服务器发送响应很好,但我的代码甚至没有输入onResponse()并引发错误。然后NPE由于缺乏响应。