和我的朋友一起,我们正在一个项目中工作,为此我需要创建一个Android应用程序。 (我指的是,我是java编程的初学者。)
首先,我要遵循一个好的教程(http://www.buildcircuit.com/sensorgraph-using-android-amarino-and-arduino/) 它解释了如何创建一个连接输入您的arduino(微控制器)和您的arduino与amarino(蓝牙)。
程序检索可变电压的值并将其显示在手机上。
但是我很麻烦,我的程序不起作用。当我在手机上传它时,它显示一个黑色窗口,显示错误消息“不幸的是,SensorGraph2已停止” 我不知道我能做什么。
这是SensorGrpah.java:
package edu.mit.media.hlt.sensorgraph;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
import at.abraxas.amarino.Amarino;
import at.abraxas.amarino.AmarinoIntent;
public class SensorGraph extends Activity {
private static final String DEVICE_ADDRESS = "00:15:FF:F2:0F:A8";
private GraphView mGraph;
private TextView mValueTV;
private ArduinoReceiver arduinoReceiver = new ArduinoReceiver();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mGraph = (GraphView)findViewById(R.id.graph);
mValueTV = (TextView) findViewById(R.id.value);
mGraph.setMaxValue(1024);
}
@Override
protected void onStart() {
super.onStart();
registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));
Amarino.connect(this, DEVICE_ADDRESS);
}
@Override
protected void onStop() {
super.onStop();
Amarino.disconnect(this, DEVICE_ADDRESS);
unregisterReceiver(arduinoReceiver);
}
public class ArduinoReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String data = null;
final int dataType = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1);
if (dataType == AmarinoIntent.STRING_EXTRA){
data = intent.getStringExtra(AmarinoIntent.EXTRA_DATA);
if (data != null){
mValueTV.setText(data);
try {
final int sensorReading = Integer.parseInt(data);
mGraph.addDataPoint(sensorReading);
}
catch (NumberFormatException e) { /* oh data was not an integer */ }
}
}
}
}
}
和main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<edu.mit.media.hlt.sensorgraph.GraphView
android:id="@+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="4"
/>
<TextView
android:id="@+id/value"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="6"
android:text="@string/hello"
android:textSize="40sp"
android:gravity="center"
android:background="#fff"
/>
</LinearLayout>
以及当我尝试将其上传到手机上时的logCat
05-14 00:30:56.640: E/AndroidRuntime(29568): FATAL EXCEPTION: main
05-14 00:30:56.640: E/AndroidRuntime(29568): java.lang.NoClassDefFoundError: at.abraxas.amarino.Amarino
05-14 00:30:56.640: E/AndroidRuntime(29568): at edu.mit.media.hlt.sensorgraph.SensorGraph.onStart(SensorGraph.java:71)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1167)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.Activity.performStart(Activity.java:5216)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.ActivityThread.access$600(ActivityThread.java:140)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.os.Looper.loop(Looper.java:137)
05-14 00:30:56.640: E/AndroidRuntime(29568): at android.app.ActivityThread.main(ActivityThread.java:4898)
05-14 00:30:56.640: E/AndroidRuntime(29568): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 00:30:56.640: E/AndroidRuntime(29568): at java.lang.reflect.Method.invoke(Method.java:511)
05-14 00:30:56.640: E/AndroidRuntime(29568): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-14 00:30:56.640: E/AndroidRuntime(29568): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-14 00:30:56.640: E/AndroidRuntime(29568): at dalvik.system.NativeStart.main(Native Method)
感谢您的帮助。
答案 0 :(得分:0)
这是非常普遍的,我今天遇到了同样的麻烦。我解决了它在项目中创建文件夹libs并将AmarinoLibrary的jar添加到此文件夹而不是添加外部jar。在此之后一切正常。希望这能帮到你:)。