我正试图通过我的应用程序用蓝牙连接两部手机。我正在使用本教程: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):致命异常:线程-3652 10-11 20:03:48.640: E/AndroidRuntime(32041):java.lang.NullPointerException 10-11 20:03:48.640: E/AndroidRuntime(32041):at pl.piotrek.panitball.BluetoothConnection.uruchamianie(BluetoothConnection.java: 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):在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)区块报价
怎么了?!
发布于 2012-10-11 18:28:45
看起来您正在从以下位置调用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线程?
发布于 2012-10-11 18:40:37
不要忘记配置权限
<manifest ... >
<uses-permission android:name="android.permission.BLUETOOTH" />
...
</manifest>
https://stackoverflow.com/questions/12845953
复制相似问题