0

我在这里遇到了一些问题,因为当我在某处看到计算器代码并以某种方式使用它时,当我开始输入数字时,该应用程序总是强制关闭。帮助?

public void onClickListener8(View v)
{
    vibrator.vibrate(30);
    if(press=='=')
    {
        onClickListenerReset(buttonClear);
    }
    eight=(String)button8.getText();
    sum=sum+eight;
    editText.setText(sum);
}


04-17 15:38:23.110: E/AndroidRuntime(678): FATAL EXCEPTION: main
04-17 15:38:23.110: E/AndroidRuntime(678): java.lang.IllegalStateException: Could not     execute method of the activity
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.view.View$1.onClick(View.java:2144)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.view.View.performClick(View.java:2485)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.view.View$PerformClick.run(View.java:9080)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.os.Handler.handleCallback(Handler.java:587)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.os.Handler.dispatchMessage(Handler.java:92)
04-17 15:38:23.110: E/AndroidRuntime(678):  at android.os.Looper.loop(Looper.java:123)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.app.ActivityThread.main(ActivityThread.java:3683)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     java.lang.reflect.Method.invokeNative(Native Method)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     java.lang.reflect.Method.invoke(Method.java:507)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-17 15:38:23.110: E/AndroidRuntime(678):  at dalvik.system.NativeStart.main(Native     Method)
04-17 15:38:23.110: E/AndroidRuntime(678): Caused by:     java.lang.reflect.InvocationTargetException
04-17 15:38:23.110: E/AndroidRuntime(678):  at     java.lang.reflect.Method.invokeNative(Native Method)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     java.lang.reflect.Method.invoke(Method.java:507)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.view.View$1.onClick(View.java:2139)
04-17 15:38:23.110: E/AndroidRuntime(678):  ... 11 more
04-17 15:38:23.110: E/AndroidRuntime(678): Caused by: java.lang.SecurityException:     Requires VIBRATE permission
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.os.Parcel.readException(Parcel.java:1322)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.os.Parcel.readException(Parcel.java:1276)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.os.IVibratorService$Stub$Proxy.vibrate(IVibratorService.java:106)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     android.os.Vibrator.vibrate(Vibrator.java:52)
04-17 15:38:23.110: E/AndroidRuntime(678):  at     com.mypackage.Calculator.onClickListener8(Calculator.java:232)
04-17 15:38:23.110: E/AndroidRuntime(678):  ... 14 more
4

2 回答 2

1

Make sure your app has the Vibrate permission. The following line should be there in the manifest:

<uses-permission android:name="android.permission.VIBRATE"/>
于 2012-04-17T15:47:12.997 回答
-3

我认为您必须使用模拟器。只需注释掉振动;不知何故,这就是问题的原因。

于 2012-04-17T15:35:45.513 回答