我正在尝试通过我的应用程序通过蓝牙连接两部手机。 我正在使用本教程: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):at pl.piotrek.panitball.BluetoothConnection.uruchamianie(BluetoothConnection.java:24) 10-11 20:03:48.640:E / AndroidRuntime(32041):at pl.piotrek.panitball.MainClass.doDraw(MainClass.java:86) 10-11 20:03:48.640:E / AndroidRuntime(32041):at pl.piotrek.panitball.ViewThread.run(ViewThread.java:32) 块引用
怎么了?!
答案 0 :(得分:2)
看起来你正在致电startActivityForResult
:
pl.piotrek.panitball.MainClass.doDraw(MainClass.java:86)10-11 20:03:48.640:E / AndroidRuntime(32041):at pl.piotrek.panitball.ViewThread.run(ViewThread.java: 32)
工作线程?也许从GUI线程尝试?
答案 1 :(得分:0)
不要忘记配置权限
<manifest ... >
<uses-permission android:name="android.permission.BLUETOOTH" />
...
</manifest>