蓝牙发送数据..应用程序崩溃

时间:2016-01-17 11:46:20

标签: android android-activity bluetooth android-bluetooth

好的,所以我有2个班级,一对设备,另一个发送数据。

我的配对课程没有任何问题。

但是由于这个openBT()函数,我的发送数据类很快崩溃了,因为这个openBT()函数,我删除了它,try catch语句和我的活动再次起作用,所以我知道就是这样。

这是我的代码:

        try {
        openBT();
    } catch (IOException e)
    {
        Toast.makeText(getApplicationContext(), "Bluetooth not connected, are you sure you paired with the NPU?", Toast.LENGTH_LONG).show();
    }

    void openBT() throws IOException {

    UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
    mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
    mmSocket.connect();
    mmOutputStream = mmSocket.getOutputStream();
    mmInputStream = mmSocket.getInputStream();
}

现在......我没有连接到任何蓝牙设备,但由于try catch语句,我认为活动仍然会加载,然后只是抛出我的吐司,这意味着其他错误,这是正确的还是它仍在继续坠毁?我暂时无法在任何蓝牙设备上进行测试。

另外,我在教程中在线发现了这个openBT()代码..因为我与设备配对,这个代码足以打开与该设备的连接..使用该UUID(必须是任何配对?)

logcat的:

E/AndroidRuntime: FATAL EXCEPTION: main
                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{funnysystems.fun/funnysystems.fun.NPUBTControl}: java.lang.NullPointerException
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2224)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2274)
                                                   at android.app.ActivityThread.access$600(ActivityThread.java:150)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1276)
                                                   at android.os.Handler.dispatchMessage(Handler.java:99)
                                                   at android.os.Looper.loop(Looper.java:213)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5153)
                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:511)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                   at dalvik.system.NativeStart.main(Native Method)
                                                Caused by: java.lang.NullPointerException
                                                   at funnysystems.fun.NPUBTControl.openBT(NPUBTControl.java:82)
                                                   at funnysystems.fun.NPUBTControl.onCreate(NPUBTControl.java:56)
                                                   at android.app.Activity.performCreate(Activity.java:5104)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2188)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2274) 
                                                   at android.app.ActivityThread.access$600(ActivityThread.java:150) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1276) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                   at android.os.Looper.loop(Looper.java:213) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5153) 
                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:511) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                                                   at dalvik.system.NativeStart.main(Native Method) 

01-17 11:50:34.645 908-1429 /? W / ActivityManager:强制完成活动funnysystems.fun/.NPUBTControl

0 个答案:

没有答案