本文介绍了使用Android Volley时出现NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用android volley库发出网络请求:
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}
我正在使用最新版本的Android SDK
I am using latest version of Android SDK
推荐答案
要与 Volley 一起使用,我们需要在Android项目的应用程序模块中的gradle文件中定义依赖项:
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'
}
您可以在 此处 上查看Volley的最新版本.
you can see the latest versions of Volley here.
更多信息:
这篇关于使用Android Volley时出现NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!