我有一个称为 Checker 的方法,当我单击按钮但我的应用程序停止工作时会调用它。我已尝试添加 try catch 以查看异常,但我不明白为什么它不起作用...在方法下方,我将错误的日志 cat 放在了下面:
public void Checker()
{
EditText text = (EditText) findViewById(R.id.editText1);
int in = Integer.parseInt(text.getText().toString());
try{
if(MainActivity.result == in)
{
ProgressBar bar = (ProgressBar) findViewById(R.id.seekBar1);
MainActivity.progress = (MainActivity.progress + 1);
bar.setProgress(MainActivity.progress);
}
else
{
text.setBackgroundColor(Color.RED);
}
}catch(Exception e){System.out.println(e);}
}
日志猫:
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not find a method Checker(View) in the activity class com.taffatech.kidsapp.GameActivity for onClick handler on view class android.widget.Button with id 'btnQuestion'
at android.view.View$1.onClick(View.java:3090)
at android.view.View.performClick(View.java:3574)
at android.view.View$PerformClick.run(View.java:14293)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
HERE:
Caused by: java.lang.NoSuchMethodException: Checker [class android.view.View]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getMethod(Class.java:915)
at android.view.View$1.onClick(View.java:3083)