我只是制作了一个简单的应用程序,当单击按钮时会振动,但由于某种原因,当我单击按钮时,应用程序说它意外停止并需要强制关闭,下面是主 java 文件的源代码,我用过我的清单中的 android 振动权限。有人能告诉我为什么每次我点击振动按钮时都会出现意外停止的错误吗?
package com.test;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.EditText;
public class Main extends Activity {
public final static String EXTRA_MESSAGE = "com.test.MESSAGE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
/* Called when the user clicks the button */
public void sendMessage(View view) {
// do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
public void vibrateMe() {
Vibrator vibrate = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrate.vibrate(500);
}
public void stopVibrating(Vibrator vibrate) {
vibrate.cancel();
}
}