致命异常:主android



和我的朋友,我们在一个项目中工作,我需要创建一个android应用程序。(我指定,我是java编程的初学者)。

首先,我遵循了一个很好的教程(http://www.buildcircuit.com/sensorgraph-using-android-amarino-and-arduino/)它解释了如何使用amarino(蓝牙)创建arduino(微控制器)和arduino之间的连接。

程序检索可变电压的值并显示在手机上。

但是我遇到麻烦了,我的程序不工作了。当我把它上传到我的手机上时,它显示了一个黑色的窗口,错误信息"不幸的是,SensorGraph2已经停止"。我不知道我能做什么。

这是sensorgraph .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)

谢谢你的帮助

这是很常见的,我今天也遇到了同样的麻烦。我解决了这个问题,在项目中创建了一个文件夹libs,并将amarinlibrary的jar添加到这个文件夹中,而不是添加一个外部jar。这一切都很好。

相关内容

  • 没有找到相关文章

最新更新