NoClassDefFoundError when using Android Volley

喜你入骨 提交于 2019-12-24 05:21:11

问题


I am trying to make a network request using android volley library:

    StringRequest jsObjRequest = new StringRequest(Request.Method.GET,
                Network.getFullUrl("/Account/Login"),
                new Listener<String>() {

                    @Override
                    public void onResponse(String response) {
                        // TODO Auto-generated method stub

                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO Auto-generated method stub

                    }
                });

Network.getInstance(this).addToRequestQueue(jsObjRequest);

I have included the library in the build path under Projects. And it compiles fine,

But when I run the app I get the following error:

08-18 21:57:05.739: E/AndroidRuntime(22937): FATAL EXCEPTION: main
08-18 21:57:05.739: E/AndroidRuntime(22937): java.lang.NoClassDefFoundError:    com.android.volley.toolbox.StringRequest
08-18 21:57:05.739: E/AndroidRuntime(22937):    at com.fma.mobileapp.LoginActivity.attemptLogin(LoginActivity.java:173)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at com.fma.mobileapp.LoginActivity$2.onClick(LoginActivity.java:94)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at android.view.View.performClick(View.java:4475)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at android.view.View$PerformClick.run(View.java:18786)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at android.os.Handler.handleCallback(Handler.java:730)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at android.os.Looper.loop(Looper.java:137)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at android.app.ActivityThread.main(ActivityThread.java:5419)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at java.lang.reflect.Method.invokeNative(Native Method)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at java.lang.reflect.Method.invoke(Method.java:525)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
08-18 21:57:05.739: E/AndroidRuntime(22937):    at dalvik.system.NativeStart.main(Native Method)

[EDIT}

I am using latest version of Android SDK


回答1:


To work with Volley we need to define the dependency into the gradle file in Android project's app module:

dependencies {
    ...
    compile 'com.android.volley:volley:1.1.0'
}

you can see the latest versions of Volley here.

more information:

Transmitting Network Data Using Volley



来源:https://stackoverflow.com/questions/25371136/noclassdeffounderror-when-using-android-volley

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!