尝试将 facebook sdk 集成到 android 应用程序,但我的应用程序没有启动。有日志。如何修复此运行时异常?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView pic = (ImageView) findViewById(R.id.imageView1);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
08-15 11:48:21.712: E/AndroidRuntime(564): FATAL EXCEPTION: main
08-15 11:48:21.712: E/AndroidRuntime(564): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sri.z4globalsoft/com.sri.z4globalsoft.MainActivity}: java.lang.NullPointerException
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.os.Looper.loop(Looper.java:137)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 11:48:21.712: E/AndroidRuntime(564): at dalvik.system.NativeStart.main(Native Method)
08-15 11:48:21.712: E/AndroidRuntime(564): Caused by: java.lang.NullPointerException
08-15 11:48:21.712: E/AndroidRuntime(564): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.sri.z4globalsoft.MainActivity.<init>(MainActivity.java:23)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.Class.newInstanceImpl(Native Method)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.Class.newInstance(Class.java:1319)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-15 11:48:21.712: E/AndroidRuntime(564): ... 11 more
尝试根据您在下面给出的答案更改代码应用程序然后也有问题
08-15 12:25:00.800: E/AndroidRuntime(712): FATAL EXCEPTION: main
08-15 12:25:00.800: E/AndroidRuntime(712): java.lang.NoClassDefFoundError: com.facebook.android.Facebook
08-15 12:25:00.800: E/AndroidRuntime(712): at com.sri.z4globalsoft.MainActivity.<init>(MainActivity.java:25)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.Class.newInstanceImpl(Native Method)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.Class.newInstance(Class.java:1319)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.os.Looper.loop(Looper.java:137)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 12:25:00.800: E/AndroidRuntime(712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 12:25:00.800: E/AndroidRuntime(712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 12:25:00.800: E/AndroidRuntime(712): at dalvik.system.NativeStart.main(Native Method)