0
我創建的應用程序與藍牙,但是藍牙時閉合,APK緊密,烤麪包,我有這個錯誤... java.lang.NullPointerException
在io.webbt.Activity2.openBT
如何修復錯誤打開藍牙?
void findBT()
{
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter == null)
{
myLabel.setText("No bluetooth adapter available");
}
if(!mBluetoothAdapter.isEnabled())
{
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBluetooth, REQUEST_ENABLE_BT);
}
}
我有一個消息,如果我想打開藍牙我選擇是的......但沒有繼續我的活動......任何幫助?如果我關閉藍牙,我該如何回到我的活動?
01-16 15:36:08.483: W/dalvikvm(3677): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
01-16 15:36:08.483: E/AndroidRuntime(3677): FATAL EXCEPTION: main
01-16 15:36:08.483: E/AndroidRuntime(3677): java.lang.RuntimeException: Unable to start activity ComponentInfo{io.webbt/io.webbt.Activity2}: java.lang.NullPointerException
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.os.Looper.loop(Looper.java:137)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.ActivityThread.main(ActivityThread.java:4441)
01-16 15:36:08.483: E/AndroidRuntime(3677): at java.lang.reflect.Method.invokeNative(Native Method)
01-16 15:36:08.483: E/AndroidRuntime(3677): at java.lang.reflect.Method.invoke(Method.java:511)
01-16 15:36:08.483: E/AndroidRuntime(3677): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-16 15:36:08.483: E/AndroidRuntime(3677): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-16 15:36:08.483: E/AndroidRuntime(3677): at dalvik.system.NativeStart.main(Native Method)
01-16 15:36:08.483: E/AndroidRuntime(3677): Caused by: java.lang.NullPointerException
01-16 15:36:08.483: E/AndroidRuntime(3677): at io.webbt.Activity2.openBT(Activity2.java:192)
01-16 15:36:08.483: E/AndroidRuntime(3677): at io.webbt.Activity2.onStart(Activity2.java:130)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.Activity.performStart(Activity.java:4475)
01-16 15:36:08.483: E/AndroidRuntime(3677): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1940)
01-16 15:36:08.483: E/AndroidRuntime(3677): ... 11 more
void openBT() throws IOException
{
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standar
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mmSocket.connect();
mmOutputStream = mmSocket.getOutputStream();
mmInputStream = mmSocket.getInputStream();
myLabel.setText("Bluetooth Opened");
protected void onStart() {
super.onStart();
try
{
//findBT();
openBT();
}
catch (IOException ex) { }
runnable.run();
}
請張貼logcat的輸出 –
沒有ü添加此權限<使用說明 - 權限android:name =「android.permission.BLUETOOTH」/> <使用權限android:name =「android.permission.BLUETOOTH_ADMIN」/> –
權限正常 – user1977741