Question

So im developing a android application and im using a tabhost. To handle the activity's i created a activitygroup from every tab.

From these "parent" activity's i go to child acivity's.

on this child acitivy i have a page with a spinner and a button.

First the button was working but when i clicked on the spinner the application would crash. To fix this i had to change

setContentView(R.layout.sho_add_exercise_event); 

to

View contentView = LayoutInflater.from(getParent()).inflate(R.layout.show_add_exercise_event, null);
setContentView(contentView);

now my spinner is working but when i click on the button the application will crash.

This is the log output

04-05 12:42:58.890: E/AndroidRuntime(4485): Uncaught handler: thread main exiting due to uncaught exception
04-05 12:42:58.930: E/AndroidRuntime(4485): java.lang.IllegalStateException: Could not find a method onClickAdd(View) in the activity
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.View$1.onClick(View.java:2016)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.View.performClick(View.java:2344)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.View.onTouchEvent(View.java:4133)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.widget.TextView.onTouchEvent(TextView.java:6510)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.View.dispatchTouchEvent(View.java:3672)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent

04-05 12:42:58.930: E/AndroidRuntime(4485): Caused by: java.lang.NoSuchMethodException: onClickAdd
04-05 12:42:58.930: E/AndroidRuntime(4485):     at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at java.lang.Class.getMethod(Class.java:1007)
04-05 12:42:58.930: E/AndroidRuntime(4485):     at android.view.View$1.onClick(View.java:2013)
04-05 12:42:58.930: E/AndroidRuntime(4485):     ... 37 more

EDIT:

i got this method in the activity but he doesnt find the method becaus i did View contentView = LayoutInflater.from(getParent()).inflate(R.layout.show_add_exercise_event, null); setContentView(contentView);

Hope some1 can help me :D!

Was it helpful?

Solution 2

I found the solution.

I deleted the onClick in the xml file. And added a setOnClickListener in my java code.

This did the job :) hope this helps some1 else out to!

OTHER TIPS

Message is self-explanatory: Could not find a method onClickAdd(View) in the activity

Declare a method with this event:

public void onClickAdd(View v)
{
   .......
   .......
}

Because somewhere you have declared onClickAdd() method for Add button i think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top