2012-04-17 221 views
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 
+0

讓你的「亞行logcat」輸出的副本,並張貼在這裏,你的應用程序有一個bug ...... – 2012-04-17 15:35:21

回答

1

確保您的應用具有振動權限。下面的行應該有在清單:

<uses-permission android:name="android.permission.VIBRATE"/> 
+0

是的,看看日誌,它清楚地說: 需要VIBRATE許可 – ekawas 2012-04-17 15:56:15

-3

我認爲你必須使用模擬器。只是評論振動;不知何故,這是問題的原因。

+0

嘿感謝的人,您R右 – 2012-04-17 15:43:46

+0

但如何來吧它會導致這種問題我敦有這個問題,當我的手機上運行 – 2012-04-17 15:44:22

+0

我也不是很確定ABT這,但我知道如果你使用原來的設置不知何故振動會導致你的錯誤也顯示在你的logcat – user1235085 2012-04-17 15:45:52