当我实例化RestAdapter
时,我的应用程序总是崩溃private void submitForm(SignupForm form){
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(ENDPOINT)
.build();
SignUpApi signUpApi = adapter.create(SignUpApi.class);
signUpApi.sendStudentForm(form);
}
我还包括了retrofit.jar文件和Gson.jar文件。 有类似的问题here,但我不使用gradle。
堆栈追踪:
02-06 13:04:13.021:D / mali_winsys(22638):new_window_surface返回0x3000
02-06 13:04:16.876:E / dalvikvm(22638):找不到类'retrofit.RestAdapter $ Builder',从方法com.example.squiz.SignupActivity.submitForm引用
02-06 13:04:16.876:W / dalvikvm(22638):VFY:无法在Lcom / example / squiz / SignupActivity中解析新实例55(Lretrofit / RestAdapter $ Builder;);
02-06 13:04:16.876:D / dalvikvm(22638):VFY:在0x0000处替换操作码0x22
02-06 13:04:16.881:D / dalvikvm(22638):DexOpt:在Lcom / example / squiz / SignupActivity; .submitForm
中无法选择直接调用0x004c在0x0202-06 13:04:16.881:W / ApplicationPackageManager(22638):getCSCPackageItemText()
02-06 13:04:16.956:D / mali_winsys(22638):new_window_surface返回0x3000
02-06 13:04:18.596:D / AndroidRuntime(22638):关闭虚拟机
02-06 13:04:18.596:W / dalvikvm(22638):threadid = 1:线程退出,未捕获异常(group = 0x416cfc08)
02-06 13:04:18.596:E / AndroidRuntime(22638):致命异常:主
02-06 13:04:18.596:E / AndroidRuntime(22638):进程:com.example.squiz,PID:22638
02-06 13:04:18.596:E / AndroidRuntime(22638):java.lang.NoClassDefFoundError:retrofit.RestAdapter $ Builder
02-06 13:04:18.596:E / AndroidRuntime(22638):at com.example.squiz.SignupActivity.submitForm(SignupActivity.java:66)
02-06 13:04:18.596:E / AndroidRuntime(22638):at com.example.squiz.SignupActivity.access $ 5(SignupActivity.java:65)
02-06 13:04:18.596:E / AndroidRuntime(22638):at com.example.squiz.SignupActivity $ 1.onClick(SignupActivity.java:55)
02-06 13:04:18.596:E / AndroidRuntime(22638):在android.view.View.performClick(View.java:4630)
02-06 13:04:18.596:E / AndroidRuntime(22638):在android.view.View $ PerformClick.run(View.java:19339)
02-06 13:04:18.596:E / AndroidRuntime(22638):在android.os.Handler.handleCallback(Handler.java:733)
02-06 13:04:18.596:E / AndroidRuntime(22638):在android.os.Handler.dispatchMessage(Handler.java:95)
02-06 13:04:18.596:E / AndroidRuntime(22638):在android.os.Looper.loop(Looper.java:157)
02-06 13:04:18.596:E / AndroidRuntime(22638):在android.app.ActivityThread.main(ActivityThread.java:5335)
02-06 13:04:18.596:E / AndroidRuntime(22638):at java.lang.reflect.Method.invokeNative(Native Method)
02-06 13:04:18.596:E / AndroidRuntime(22638):at java.lang.reflect.Method.invoke(Method.java:515)
02-06 13:04:18.596:E / AndroidRuntime(22638):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1265)
02-06 13:04:18.596:E / AndroidRuntime(22638):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
02-06 13:04:18.596:E / AndroidRuntime(22638):at dalvik.system.NativeStart.main(Native Method)
02-06 13:04:19.896:I / Process(22638):发送信号。 PID:22638 SIG:9
02-06 13:04:20.181:W / ApplicationPackageManager(25502):getCSCPackageItemText()
02-06 13:04:20.181:I / PersonaManager(25502):getPersonaService()name persona_policy
02-06 13:04:20.226:D / dalvikvm(25502):GC_FOR_ALLOC释放51K,7%免费16826K / 18032K,暂停19ms,总计19ms
02-06 13:04:20.256:I / dalvikvm-heap(25502):将堆(frag case)增长到24.879MB,用于7680016字节分配
02-06 13:04:20.266:D / dalvikvm(25502):GC_FOR_ALLOC释放< 1K,5%free 24326K / 25536K,暂停10ms,总计10ms
02-06 13:04:20.351:I /(25502):PLATFORM VERSION:JB-MR-2
02-06 13:04:20.366:D / mali_winsys(25502):new_window_surface返回0x3000
02-06 13:04:20.391:D / OpenGLRenderer(25502):启用调试模式0
答案 0 :(得分:0)
我通过添加
解决了这个问题packagingOptions {
exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.properties'
exclude 'META-INF/maven/com.squareup.retrofit/retrofit/pom.xml'
}
在gradle中。
我的网络库
compile 'com.squareup.okio:okio:1.6.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'