0

我有一个应用程序,它根据RadioButtonRadioGroup.

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]
4

1 回答 1

1

让我说一下我的想法。由于您正在使用RadioGroupie RadioButtons ,因此有一种选择。现在,覆盖onCheckedChanged(RadioGroup group, int checkedId) 并根据值checkedId确定要采取的执行路径。如果您decisions基于 id(来自 xml)或组中的唯一 ID 号进行操作,则相同。这对你有意义吗?我希望你能得到我想说的,它也有帮助。

于 2011-07-23T03:06:02.187 回答