我有一个尝试使用 Volley 的 Maven 项目。这是我第一次使用。我将 Volley 添加到本地存储库,并在项目的 pom.xml 文件中添加了依赖项。一切都编译得很好,但是每当我尝试创建一个新的 Request 对象时,我都会在超类 Request 对象上得到一个 NullPointerException 。有什么帮助吗?
编辑:这是我的堆栈跟踪
8-29 22:14:58.830: ERROR/AndroidRuntime(696): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lhs.app/com.lhs.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.android.volley.Request.<init>(Request.java:129)
at com.android.volley.toolbox.JsonRequest.<init>(JsonRequest.java:58)
at com.android.volley.toolbox.JsonObjectRequest.<init>(JsonObjectRequest.java:47)
at com.lhs.app.MainActivity.startRequest(MainActivity.java:35)
at com.lhs.app.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)