我正在尝试在 android 中激活振动,但每次按下按钮时应用程序崩溃.....
silet.setRingerMode(AudioManager.RINGER_MODE_VIBRATE)
我也做了进口的事情。并声明:
public AudioManager silent;
日志猫:
07-13 22:06:17.956: E/AndroidRuntime(11925): FATAL EXCEPTION: main
07-13 22:06:17.956: E/AndroidRuntime(11925): java.lang.IllegalStateException: Could not execute method of the activity
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.view.View$1.onClick(View.java:2072)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.view.View.performClick(View.java:2408)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.view.View$PerformClick.run(View.java:8816)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.os.Handler.handleCallback(Handler.java:587)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.os.Handler.dispatchMessage(Handler.java:92)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.os.Looper.loop(Looper.java:123)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-13 22:06:17.956: E/AndroidRuntime(11925): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 22:06:17.956: E/AndroidRuntime(11925): at java.lang.reflect.Method.invoke(Method.java:521)
07-13 22:06:17.956: E/AndroidRuntime(11925): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-13 22:06:17.956: E/AndroidRuntime(11925): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-13 22:06:17.956: E/AndroidRuntime(11925): at dalvik.system.NativeStart.main(Native Method)
07-13 22:06:17.956: E/AndroidRuntime(11925): Caused by: java.lang.reflect.InvocationTargetException
07-13 22:06:17.956: E/AndroidRuntime(11925): at com.android.hello.MainActivity.click(MainActivity.java:25)
07-13 22:06:17.956: E/AndroidRuntime(11925): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 22:06:17.956: E/AndroidRuntime(11925): at java.lang.reflect.Method.invoke(Method.java:521)
07-13 22:06:17.956: E/AndroidRuntime(11925): at android.view.View$1.onClick(View.java:2067)
07-13 22:06:17.956: E/AndroidRuntime(11925): ... 11 more
07-13 22:06:17.956: E/AndroidRuntime(11925): Caused by: java.lang.NullPointerException