【发布时间】:2014-05-27 18:32:49
【问题描述】:
我刚刚完成了我的应用程序,我准备发布它。现在,我决定让我的应用程序与 10 英寸平板电脑兼容,当我打开我的第一个活动(在 Nexus10 的模拟器上)时,它会正确显示所有内容(即使它必须将方向从纵向更改为横向),但是当我开始我的第二个活动,它崩溃了。在 LogCat 上,我看到问题是一个 ImageButton,通常可以在任何其他设备上工作。
Activity.java:
ImageButton bulb = (ImageButton) findViewById(R.id.bulb1);
bulb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//ecc... In-app purchase
Activity.xml:
<ImageButton
android:id="@+id/bulb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lightbulb"
android:layout_centerHorizontal="true"
android:layout_alignTop="@+id/textView1"
android:background="@drawable/lightbulb"
/>
和 Logcat:
05-27 14:18:22.949: E/AndroidRuntime(965): FATAL EXCEPTION: main
05-27 14:18:22.949: E/AndroidRuntime(965): Process: com.lifeapps.appquiz, PID: 965
05-27 14:18:22.949: E/AndroidRuntime(965): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lifeapps.appquiz/com.lifeapps.appquiz.Levels}: java.lang.NullPointerException
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.os.Handler.dispatchMessage(Handler.java:102)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.os.Looper.loop(Looper.java:136)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-27 14:18:22.949: E/AndroidRuntime(965): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 14:18:22.949: E/AndroidRuntime(965): at java.lang.reflect.Method.invoke(Method.java:515)
05-27 14:18:22.949: E/AndroidRuntime(965): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-27 14:18:22.949: E/AndroidRuntime(965): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-27 14:18:22.949: E/AndroidRuntime(965): at dalvik.system.NativeStart.main(Native Method)
05-27 14:18:22.949: E/AndroidRuntime(965): Caused by: java.lang.NullPointerException
05-27 14:18:22.949: E/AndroidRuntime(965): at com.lifeapps.appquiz.Levels.onCreate(Levels.java:133)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.Activity.performCreate(Activity.java:5231)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-27 14:18:22.949: E/AndroidRuntime(965): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-27 14:18:22.949: E/AndroidRuntime(965): ... 11 more
有什么帮助吗?我再说一遍,这只发生在 10 英寸平板电脑上。
【问题讨论】: