こんにちは私はアンドロイド開発に不慣れで、ボタンとアニメーションを備えた基本的なアプリを作成していますが、1つのボタンはアニメーションで動作しますが、もう1つのボタンはアプリを完全に停止し、エラーはありません. Btn 1 (ボタン 1) は機能しますが、Btn 2 (ボタン 2) はアプリを停止します。Javaコードは以下です。事前に感謝します。
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);}
});}{;
};
});}};
ログキャット
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