Reputation: 143
Hi I am new to android development and I am creating a basic app with buttons and animation however, one button works with animation but the other button stops the app completely and there is no error. Btn 1 (Button 1) works but Btn 2 (Button 2) stops the app. The java code is below. Any help is appreciated, thanks in advance.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Animation animAlpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
Button btn1 = (Button) findViewById(R.id.categories);
btn1.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View arg0) {
arg0.startAnimation(animAlpha);
Intent intent = new Intent(getApplicationContext(), Categories.class);
Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(25);
Button btn1= (Button) findViewById(R.id.categories);
btn1.setBackgroundResource(R.drawable.button_shape2);
startActivity(intent);
Button btn2 = (Button) findViewById(R.id.feedback);
btn2.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View arg0) {
arg0.startAnimation(animAlpha);
Intent intent = new Intent(getApplicationContext(), Feedback.class);
Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(25);
Button btn2= (Button) findViewById(R.id.feedback);
btn2.setBackgroundResource(R.drawable.button_shape2);
startActivity(intent);}
});}{;
};
});}};
Logcat
05-03 16:41:02.699: E/AndroidRuntime(24118): FATAL EXCEPTION: main
05-03 16:41:02.699: E/AndroidRuntime(24118): java.lang.IllegalStateException: Could not find a method Feedback(View) in the activity class com.android.motivateme3.MainActivity for onClick handler on view class android.widget.Button with id 'feedback'
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.view.View$1.onClick(View.java:3090)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.view.View.performClick(View.java:3574)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.view.View$PerformClick.run(View.java:14293)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.os.Handler.handleCallback(Handler.java:605)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.os.Handler.dispatchMessage(Handler.java:92)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.os.Looper.loop(Looper.java:137)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.app.ActivityThread.main(ActivityThread.java:4441)
05-03 16:41:02.699: E/AndroidRuntime(24118): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 16:41:02.699: E/AndroidRuntime(24118): at java.lang.reflect.Method.invoke(Method.java:511)
05-03 16:41:02.699: E/AndroidRuntime(24118): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
05-03 16:41:02.699: E/AndroidRuntime(24118): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
05-03 16:41:02.699: E/AndroidRuntime(24118): at dalvik.system.NativeStart.main(Native Method)
05-03 16:41:02.699: E/AndroidRuntime(24118): Caused by: java.lang.NoSuchMethodException: Feedback [class android.view.View]
05-03 16:41:02.699: E/AndroidRuntime(24118): at java.lang.Class.getConstructorOrMethod(Class.java:460)
05-03 16:41:02.699: E/AndroidRuntime(24118): at java.lang.Class.getMethod(Class.java:915)
05-03 16:41:02.699: E/AndroidRuntime(24118): at android.view.View$1.onClick(View.java:3083)
05-03 16:41:02.699: E/AndroidRuntime(24118): ... 11 more
05-03 16:41:03.889: I/Process(24118): Sending signal. PID: 24118 SIG: 9
Upvotes: 0
Views: 96
Reputation: 4389
Caused by: java.lang.NoSuchMethodException: Feedback
Does your xml mention that onClick, the button should call the method feedback ? Because that's the issue, this method does not exist, making the app crash.
Implement it to solve this issue.
Upvotes: 1