我正在尝试通过我的应用程序通过蓝牙连接两部手机。我正在使用本教程: http: //developer.android.com/guide/topics/connectivity/bluetooth.html,但我必须做错事,因为它不起作用。我想显示“启用蓝牙对话框”:
private static final int REQUEST_ENABLE_BT = 1;
[...]
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Log.v("BC", "Your device don't have bt");
}
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
并且有一个错误:
10-11 20:03:48.640: E/AndroidRuntime(32041): 致命异常: Thread-3652 10-11 20:03:48.640: E/AndroidRuntime(32041): java.lang.NullPointerException 10-11 20:03: 48.640: E/AndroidRuntime(32041): 在 android.app.Activity.startActivityForResult(Activity.java:3190) 10-11 20:03:48.640: E/AndroidRuntime(32041): 在 pl.piotrek.panitball.BluetoothConnection.uruchamianie (BluetoothConnection.java:24) 10-11 20:03:48.640: E/AndroidRuntime(32041): 在 pl.piotrek.panitball.MainClass.doDraw(MainClass.java:86) 10-11 20:03:48.640: E /AndroidRuntime(32041): 在 pl.piotrek.panitball.ViewThread.run(ViewThread.java:32) 块引用
怎么了?!