在Java中使用Android文本视图时出错
我很确定switch语句的这一部分有问题,但我被难住了,我只需要有人检查一下
switch(buttonId)
{
/* LOTS OF CASES HERE */
default:
case R.id.goButton:
TextView rootNum = (TextView)findViewById(R.id.otherView);
String rootDone = rootNum.getText().toString();
it = Integer.parseInt(rootDone);
break;
}
你能看出什么不对劲吗
更新
很抱歉没有发布日志,我认为问题很明显,但似乎不是这样
以下是两个logcat错误:
java.lang.IllegalStateException: Could not find a method RootMe(View) in the activity class root.me.RootMeActivity for onClick handler on view class 安卓.widget.Button with id 'goButton'
Caused by: java.lang.NoSuchMethodException: RootMe [class 安卓.view.View]
# 1 楼答案
问题是,在xml中,您提到了goButton的onclick事件来调用RootMe方法
(android:onClick="RootMe")
,但您尚未在活动中定义该方法。 所以从XML中删除android:onClick="RootMe"
,并将onClickListener分配给活动中的按钮示例代码
XML
源代码
# 2 楼答案
在默认值后写关键字“break”