和我的朋友一起,我们正在一个项目中工作,为此我需要创建一个 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)
谢谢你帮助我。