我在为android创建应用程序时遇到了一些麻烦,我想使用JsonFactory,但在创建JsonFactory时应用程序就崩溃了。
我进口:
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
然后我用了:
private static final JsonFactory factory = new JacksonFactory();
我还在构建路径中添加了"google-http-client-jackson2-1.16.0-rc.jar"one_answers"google-hhttp-client-1.6.0-rc.jar"库。
因此模拟器和物理设备都会给出"不幸的是,##apname##已经停止"
Logcat给出以下内容:
08-29 13:28:27.754: E/AndroidRuntime(990): FATAL EXCEPTION: main
08-29 13:28:27.754: E/AndroidRuntime(990): java.lang.ExceptionInInitializerError
08-29 13:28:27.754: E/AndroidRuntime(990): at java.lang.Class.newInstanceImpl(Native Method)
08-29 13:28:27.754: E/AndroidRuntime(990): at java.lang.Class.newInstance(Class.java:1319)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.os.Looper.loop(Looper.java:137)
08-29 13:28:27.754: E/AndroidRuntime(990): at android.app.ActivityThread.main(ActivityThread.java:5039)
08-29 13:28:27.754: E/AndroidRuntime(990): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 13:28:27.754: E/AndroidRuntime(990): at java.lang.reflect.Method.invoke(Method.java:511)
08-29 13:28:27.754: E/AndroidRuntime(990): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-29 13:28:27.754: E/AndroidRuntime(990): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-29 13:28:27.754: E/AndroidRuntime(990): at dalvik.system.NativeStart.main(Native Method)
08-29 13:28:27.754: E/AndroidRuntime(990): Caused by: java.lang.NoClassDefFoundError: com.fasterxml.jackson.core.JsonFactory
08-29 13:28:27.754: E/AndroidRuntime(990): at com.google.api.client.json.jackson2.JacksonFactory.<init>(JacksonFactory.java:45)
08-29 13:28:27.754: E/AndroidRuntime(990): at com.example.youtubesearch.MainActivity.<clinit>(MainActivity.java:42)
08-29 13:28:27.754: E/AndroidRuntime(990): ... 15 more
08-29 13:28:27.764: W/ActivityManager(288): Force finishing activity com.example.youtubesearch/.MainActivity
非常感谢您的帮助!!提前感谢
解决方案相当简单:
从logcat中,您可以看到缺少以下内容:
com.fasterxml.jackson.core.JsonFactory
所以我只是把它添加到我的构建路径中
对不起,如果我浪费了任何人的时间