0

我有一個應用程序根據RadioGroup中選定的RadioButton確定執行哪個執行路徑。InvocationTargetException當確定在RadioGroup中檢查哪個按鈕時

該計劃力與InvocationTargetException關閉時,下面的代碼片段運行:

private int getselctedRadioButtonId() { 
    RadioGroup group = (RadioGroup) findViewById(R.id.radioGroup1); 
    return group.getCheckedRadioButtonId(); 
} 

我在做什麼錯?

我可以發表更多的代碼,但我認爲這是有問題的部分。

我針對Android 2.2。

編輯:這裏的主線程完整的堆棧跟蹤:

Thread [<1> main] (Suspended (exception IllegalStateException)) 
View$1.onClick(View) line: 2072 
Button(View).performClick() line: 2408 
View$PerformClick.run() line: 8816 
ViewRoot(Handler).handleCallback(Message) line: 587 
ViewRoot(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 4627  
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
Method.invoke(Object, Object...) line: 521 
ZygoteInit$MethodAndArgsCaller.run() line: 868 
ZygoteInit.main(String[]) line: 626 
NativeStart.main(String[]) line: not available [native method] 
+0

InvocationTargetException封裝了另一個異常,你能告訴我們什麼是基礎異常嗎? – MByD

+0

@MByD我該怎麼做?我正在使用Eclipse和ADT插件。 –

+0

在Eclipse上進行調試。當你看到Debug窗口出現異常時。或者,查看debug/DDMS窗口中的logcat框。 – MByD

回答

1

讓我說什麼,我都記在心裏。由於您正在與RadioGroup合作,即RadioButtons 有一個選項。現在,覆蓋onCheckedChanged(RadioGroup group, int checkedId) 並根據checkedId的值確定採取哪個執行路徑。這也是一樣的,如果你基於組中的id(來自xml)或者唯一的id號碼來做decisions。這對你有意義嗎?我希望你能得到我想說的話,這也有幫助。

+0

你親自嘗試過嗎?我試過了,但也沒有奏效。 –

+0

它只是一個想法,可能會避免'group.getCheckedRadioButtonId();的異常和用法''這只是另一種方式。如果你試着用'group.getCheckedRadioButtonId()'告訴你,''可能不會工作,同樣的異常將被拋出。不要這樣做。 –

+0

不,我沒有使用'getCheckedRadioButtonId()',這是另一個問題,但它終於奏效了,謝謝。 –

相關問題