关于android:强制关闭onClick的ImageButton,无法弄清楚为什么

Force close onClick of ImageButton, can't figure out why

我正在尝试用ImageButtons做一个简单的动画,当我设置它时,如果我只是触摸屏幕,它工作得很好,但如果我尝试在onClick上做,应用程序就会关闭。

main.xml中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal">
       <ImageButton
        android:id="@+id/plus1"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:src="@drawable/plus"
        android:visibility="visible"
        android:gravity="center_horizontal"
        android:onClick="RunAnimations"
        />

    <ImageButton
        android:id="@+id/gears1"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:gravity="center_horizontal"
        android:src="@drawable/gears"
        android:textSize="42sp" />
    </LinearLayout>

translate.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromYDelta="-100%"
    android:toYDelta="0%"
    android:duration="1000"
    android:zAdjustment="top">
</translate>

<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="1000">
</alpha>
</set>

主要活动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    public class AnimationtestActivity extends Activity  {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
        private void RunAnimations() {
            Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
            View ib = findViewById(R.id.gears1);
            ib.clearAnimation();
            ib.startAnimation(a);    
        }
    }

编辑:

我修好了
private void RunAnimations(查看视图)

但它仍然强行关闭

编辑2:logcat的内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
03-08 13:07:33.968: E/AndroidRuntime(29270): FATAL EXCEPTION: main
03-08 13:07:33.968: E/AndroidRuntime(29270): java.lang.IllegalStateException: Could not find a method RunAnimations(View) in the activity class com.test.AnimationtestActivity for onClick handler on view class android.widget.ImageButton with id 'plus1'
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View$1.onClick(View.java:3026)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View.performClick(View.java:3480)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View$PerformClick.run(View.java:13983)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.os.Handler.handleCallback(Handler.java:605)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.os.Looper.loop(Looper.java:137)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.app.ActivityThread.main(ActivityThread.java:4340)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.reflect.Method.invokeNative(Native Method)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.reflect.Method.invoke(Method.java:511)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at dalvik.system.NativeStart.main(Native Method)
03-08 13:07:33.968: E/AndroidRuntime(29270): Caused by: java.lang.NoSuchMethodException: RunAnimations [class android.view.View]
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.Class.getConstructorOrMethod(Class.java:460)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.Class.getMethod(Class.java:915)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View$1.onClick(View.java:3019)
03-08 13:07:33.968: E/AndroidRuntime(29270):    ... 11 more

框架找不到您的单击处理程序方法,因为它具有错误的签名。 声明如下:

1
2
3
public void RunAnimations(View view) {
    . . .
}