我修改了我的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