我正在研究的项目存在很大问题。 这是一个使用蓝牙与arduino通信的项目,应用程序必须检测对象的颜色。
我没有Android手机所以我正在使用模拟器(Nexus5_API_23),但是当我尝试启动应用程序时,我收到一条错误消息以及android监视器中的内容。 你们有什么想法可以解决这个问题吗?
PS:我知道模拟器无法模拟蓝牙,但这真的是问题吗?
05-10 15:47:08.185 2767-2767/com.example.caroline.colorfinder I/art: Not late-enabling -Xcheck:jni (already on)
05-10 15:47:08.403 2767-2767/com.example.caroline.colorfinder D/CameraBridge: Attr count: 3
05-10 15:47:08.410 2767-2767/com.example.caroline.colorfinder E/BluetoothAdapter: Bluetooth binder is null
05-10 15:47:08.410 2767-2767/com.example.caroline.colorfinder D/OCVSample::Activity: Sorry, No Bluetooth antenna found!
05-10 15:47:08.410 2767-2767/com.example.caroline.colorfinder D/AndroidRuntime: Shutting down VM
05-10 15:47:08.410 2767-2767/com.example.caroline.colorfinder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.caroline.colorfinder, PID: 2767
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.caroline.colorfinder/com.example.caroline.colorfinder.ColorFinderActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothAdapter.isEnabled()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothAdapter.isEnabled()' on a null object reference
at com.example.caroline.colorfinder.ColorFinderActivity.onCreate(ColorFinderActivity.java:133)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav a:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:1)
java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.caroline.colorfinder / com.example.caroline.colorfinder.ColorFinderActivity}:java.lang.NullPointerException:尝试调用虚方法' boolean android.bluetooth.BluetoothAdapter.isEnabled()'在空对象引用上
这意味着BluetoothAdapter不会被初始化。
记得称之为:
BluetoothAdapter adapter = new BluetoothAdapter(params);
对于蓝牙,您可能需要此权限:
<uses-permission android:name="android.permission.BLUETOOTH" />