I have this method called Checker that gets called when I click a button but my app stops working. I have tried adding the try catch to see the exception but I cannot understand why it is not working... Below the method I have put the log cat of the errors:
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);}
}
LogCat:
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)
I don't know where are you calling this method, but it seems that the app is looking for:
void Checker(View)
but you are implementing this:
void Checker()
have you debugged the application so you can make sure it is entering on the method you created?
Another thing is, you should, by convention name Java methods starting with lowercase. I don't think this is the problem but you should get used to.
Hope this helps