简体   繁体   English

打开amarino连接时Android应用程序强制关闭

[英]Android app force closing when opening amarino connection

I am new to android development, and have run into a problem I seem unable to solve. 我是Android开发的新手,遇到了我似乎无法解决的问题。 My android app should be able to communicate with my arduino device, sending info to and retrieving info from my device. 我的Android应用程序应该能够与我的arduino设备进行通信,向我的设备发送信息并从我的设备中检索信息。 I have set up my connection between the two with a bluetooth device and I am using amarino to facilitate the communication. 我已经使用蓝牙设备在两者之间建立了连接,并且我正在使用amarino来促进通信。

Now I can connect with amarino and send data and receive data, now I want to do this from my app. 现在,我可以连接amarino并发送数据和接收数据,现在我想通过我的应用程序执行此操作。 The problem comes when I enter this line: 当我输入此行时,问题就来了:

private static final String DEVICE_ADDRESS = "07:12:04:16:68:18"; 
Amarino.connect(this, DEVICE_ADDRESS);

The number is the MAC address of my bluetooth adapter connected to my arduino device. 该数字是连接到arduino设备的蓝牙适配器的MAC地址。 As soon as I run my app on my phone it just force closes due to unexpected error. 一旦我在手机上运行我的应用程序,由于意外错误,它将强制关闭。 Now as I said, I am a bit of a noob when it comes to android, so I installed logCat to try get some log info out of it. 现在,正如我所说的,对于android,我有点菜鸟,所以我安装了logCat尝试从中获取一些日志信息。 All I got from it was this somewhat unhelpful error message: 我得到的只是这个有点无益的错误消息:

com.example.projectgreetv3/.StartingPlace 10-24 15:22:55.140 E/AndroidRuntime(4906): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.projectgreetv3/com.example.projectgreetv3.StartingPlace}: java.lang.ClassNotFoundException: com.example.projectgreetv3.StartingPlace in loader dalvik.system.PathClassLoader[/data/app/com.example.projectgreetv3-1.apk] 10-24 15:22:55.140 E/AndroidRuntime(4906): Caused by: java.lang.ClassNotFoundException: com.example.projectgreetv3.StartingPlace in loader dalvik.system.PathClassLoader[/data/app/com.example.projectgreetv3-1.apk] 10-24 15:22:55.148 W/ActivityManager(539): Force finishing activity com.example.projectgreetv3/.StartingPlace 10-24 15:21:51.726 I/UinboxLogger(4585): [UinboxReceiver] onReceive() >> intent.getData() : com.example.projectgreetv3 10-24 15:21:52.382 I/UninstallAppProgress(4575): Finished uninstalling pkg: com.example.projectgreetv3 10-24 15:22:52.523 D/PackageManager(539): Scanning package com.examp com.example.projectgreetv3 / .StartingPlace 10-24 15:22:55.140 E / AndroidRuntime(4906):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.example.projectgreetv3 / com.example.projectgreetv3.StartingPlace}: java.lang.ClassNotFoundException:com.example.projectgreetv3.StartingPlace在加载程序中dalvik.system.PathClassLoader [/data/app/com.example.projectgreetv3-1.apk] 10-24 15:22:55.140 E / AndroidRuntime(4906) :原因:java.lang.ClassNotFoundException:com.example.projectgreetv3.StartingPlace在加载程序中dalvik.system.PathClassLoader [/data/app/com.example.projectgreetv3-1.apk] 10-24 15:22:55.148 W / ActivityManager(539):强制完成活动com.example.projectgreetv3 / .StartingPlace 10-24 15:21:51.726 I / UinboxLogger(4585):[UinboxReceiver] onReceive()>> intent.getData():com.example.projectgreetv3 10-24 15:21:52.382 I / UninstallAppProgress(4575):完成卸载pkg:com.example.projectgreetv3 10-24 15:22:52.523 D / PackageManager(539):扫描软件包com.examp le.projectgreetv3 le.projectgreetv3

I hope someone can help me with this, as I am on wits end. 我希望机智的人可以帮助我。

For more info on: - Arduino: - http://www.arduino.cc/ - Amarino: http://www.amarino-toolkit.net/ 有关更多信息: - Arduino的: - http://www.arduino.cc/ - Amarino: http://www.amarino-toolkit.net/

If you look a bit further down on your stacktrace (in the logcat) you will probably see that the cause of this crash is an NetworkOnMainThreadException. 如果您在堆栈跟踪中(在logcat中)往下看,您可能会看到导致崩溃的原因是NetworkOnMainThreadException。 (If you are running Android 3.0 or higher) (如果您运行的是Android 3.0或更高版本)

Please make sure that you do all your network communication on a separate thread (Thread/ASyncTask). 请确保您在单独的线程(Thread / ASyncTask)上进行所有网络通信。

http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM