我修改了我的main.xml和我的android应用程序崩溃。findViewById抛出一个RuntimeException
我运行调试,并发现它在
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663
抛出一个RuntimeException我无法理解其中的错误是在我的计划。我一分为二的代码,找到这一行把它:
giveUpButton = (Button) findViewById(R.id.GiveUpButton);
我敢肯定,因为在我删除了此行的异常消失。
我没有任何想法。为什么不是堆栈顶部findViewById
?为什么会抛出异常?
我有这样的代码main.xml中:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/give_up_button"
android:id="@+id/GiveUpButton"/>
之前如果findViewById找不到视图,它会返回null抛出一个RuntimeException来代替。我很困惑。 – 2011-05-04 17:38:02
logcat中有什么? – CaseyB 2011-05-04 17:42:07
是的,请向我们展示异常跟踪的其余部分。 – adamp 2011-05-04 18:58:35