Android 蓝牙在选项卡视图中强制关闭错误
我正在实现一个基于 GPS 的室外定位器应用程序。
我使用 tabview,其中第一个选项卡中有地图和 GPS,第二个选项卡中有蓝牙连接。
在模拟器上,第一个选项卡工作正常,第二个选项卡我无法测试。
当我在 Android 设备上启动它时,应用程序被强制关闭,我收到此错误,我不知道应用程序出了什么问题。
任何帮助将非常感谢,
`06-05 23:31:36.961: ERROR/AndroidRuntime(3889): FATAL EXCEPTION: main
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at trail.com.BluetoothChatService$AcceptThread.<init>(BluetoothChatService.java:280)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at trail.com.BluetoothChatService.start(BluetoothChatService.java:119)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at trail.com.BluetoothChat.onResume(BluetoothChat.java:144)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Activity.performResume(Activity.java:3823)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3124)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:518)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Activity.performResume(Activity.java:3823)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3124)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3149)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2064)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.os.Handler.dispatchMessage(Handler.java:99)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.os.Looper.loop(Looper.java:123)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.main(ActivityThread.java:4633)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at java.lang.reflect.Method.invokeNative(Native Method)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at java.lang.reflect.Method.invoke(Method.java:521)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at dalvik.system.NativeStart.main(Native Method)
06-05 23:31:36.971: ERROR/RequestQueueHelper(3939): [Thread-10/10] Next pending job not found!!
我在以下部分调用 listenUsingInsecureRfcommWithServiceRecord
:
public AcceptThread(boolean secure) {
BluetoothServerSocket tmp = null;
mSocketType = secure ? "Secure":"Insecure";
// Create a new listening server socket
try {
if (secure) {
tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
MY_UUID_SECURE);
} else {
tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
NAME_INSECURE, MY_UUID_INSECURE);
}
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
}
mmServerSocket = tmp;
}
I'm implementing an outdoor locator application based on GPS.
I use tabview
where in the first tab there's the map and the GPS and in the second tab Bluetooth connection.
On the emulator the first tab works just fine and the second tab I can't test.
When I launch it on Android device, the application is forced to close and I get this error and I can't figure what's wrong with the application.
Any help will be very much appreciated,
`06-05 23:31:36.961: ERROR/AndroidRuntime(3889): FATAL EXCEPTION: main
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at trail.com.BluetoothChatService$AcceptThread.<init>(BluetoothChatService.java:280)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at trail.com.BluetoothChatService.start(BluetoothChatService.java:119)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at trail.com.BluetoothChat.onResume(BluetoothChat.java:144)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Activity.performResume(Activity.java:3823)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3124)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:518)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.Activity.performResume(Activity.java:3823)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3124)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3149)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2064)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.os.Handler.dispatchMessage(Handler.java:99)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.os.Looper.loop(Looper.java:123)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at android.app.ActivityThread.main(ActivityThread.java:4633)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at java.lang.reflect.Method.invokeNative(Native Method)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at java.lang.reflect.Method.invoke(Method.java:521)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-05 23:31:36.961: ERROR/AndroidRuntime(3889): at dalvik.system.NativeStart.main(Native Method)
06-05 23:31:36.971: ERROR/RequestQueueHelper(3939): [Thread-10/10] Next pending job not found!!
I call listenUsingInsecureRfcommWithServiceRecord
at the following part:
public AcceptThread(boolean secure) {
BluetoothServerSocket tmp = null;
mSocketType = secure ? "Secure":"Insecure";
// Create a new listening server socket
try {
if (secure) {
tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
MY_UUID_SECURE);
} else {
tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
NAME_INSECURE, MY_UUID_INSECURE);
}
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
}
mmServerSocket = tmp;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能的解决方案是应用 try-catch 块并尝试运行应用程序。
另请检查您所拥有的设备的操作系统版本...
发生此致命异常的原因可能是您的设备操作系统版本较低,并且设备 ROM 中不存在该方法。
possible solution is apply try- catch block and try running the app.
Also check the os version of the device you are having ...
This fatal exception occurs due to the reason that may be your device os version is lower and the method is not there in the device ROM.