编译Android应用程序时出错

时间:2012-12-03 19:30:31

标签: java android

我正在尝试编译曾经在一个月前工作的代码,但由于某种原因我在eclipse中再次启动它,现在我收到了这些奇怪的错误。我正在制作一个应用程序,它接收加速度计数据并以图形显示它,只需这样做。因为我觉得日食不与我合作,所以这变得非常头疼。

12-03 14:17:30.046: E/AndroidRuntime(368): FATAL EXCEPTION: main
12-03 14:17:30.046: E/AndroidRuntime(368): java.lang.VerifyError:     com.example.test.Activity2
12-03 14:17:30.046: E/AndroidRuntime(368):  at java.lang.Class.newInstanceImpl(Native Method)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at java.lang.Class.newInstance(Class.java:1409)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.os.Handler.dispatchMessage(Handler.java:99)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.os.Looper.loop(Looper.java:123)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at java.lang.reflect.Method.invokeNative(Native Method)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at java.lang.reflect.Method.invoke(Method.java:507)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    12-03 14:17:30.046: E/AndroidRuntime(368):  at dalvik.system.NativeStart.main(Native Method)




package com.example.test;

import java.util.Date;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.app.Activity;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;


public class Activity2 extends Activity implements SensorEventListener{


private static TimeSeries[] timeSeries;
private static XYMultipleSeriesDataset dataset;
private static XYMultipleSeriesRenderer renderer;
private static XYSeriesRenderer rendererSeries;
private static GraphicalView view;
private static Thread mThread;
private SensorManager sensorManager;
float x;
float y;
float z;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     

   // generateCsvFile("Example1.csv");

    sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
    sensorManager.registerListener(this,
            sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_NORMAL);

    dataset = new XYMultipleSeriesDataset();

    renderer = new XYMultipleSeriesRenderer();
    renderer.setAxesColor(Color.BLUE);
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitle("Time");
    renderer.setChartTitleTextSize(15);
    renderer.setFitLegend(true);
    renderer.setGridColor(Color.LTGRAY);
    renderer.setPanEnabled(false, false);
    renderer.setPointSize((float)0.25);
    renderer.setXTitle("Time");
    renderer.setYTitle("XYZ");
    renderer.setMargins( new int []{20, 30, 15, 0});
    renderer.setZoomButtonsVisible(false);
    renderer.setBarSpacing(4);
    renderer.setShowGrid(true);


    rendererSeries = new XYSeriesRenderer();
    rendererSeries.setColor(Color.RED);
    rendererSeries.setFillPoints(true);
    rendererSeries.setPointStyle(PointStyle.CIRCLE);
    renderer.addSeriesRenderer(rendererSeries);
    rendererSeries = new XYSeriesRenderer();
    rendererSeries.setColor(Color.BLUE);
    rendererSeries.setFillPoints(true);
    rendererSeries.setPointStyle(PointStyle.CIRCLE);
    renderer.addSeriesRenderer(rendererSeries);
    rendererSeries = new XYSeriesRenderer();
    rendererSeries.setColor(Color.GREEN);
    rendererSeries.setFillPoints(true);
    rendererSeries.setPointStyle(PointStyle.CIRCLE);
    renderer.addSeriesRenderer(rendererSeries);

    timeSeries = new TimeSeries[3];
    timeSeries[0] = new TimeSeries("Random 0");
    timeSeries[1] = new TimeSeries("Random 1");
    timeSeries[2] = new TimeSeries("Random 2");
    timeSeries[0].add(new Date(), x);
    timeSeries[1].add(new Date(), y);
    timeSeries[2].add(new Date(), z);

}
/*private static void generateCsvFile(String sFileName)
{
    try
    {
        File root = Environment.getExternalStorageDirectory();
        File gpxfile = new File(root, sFileName);
        FileWriter writer = new FileWriter(gpxfile);

        writer.append("Emp_Name");
        writer.append(',');
        writer.append("Adress");
        writer.append('\n');

        writer.append("hussain");
        writer.append(',');
        writer.append("Delhi");
        writer.append('\n');

        //generate whatever data you want

        writer.flush();
        writer.close();
    }
    catch(IOException e)
    {
        e.printStackTrace();
    } 
 }
 */
public void onAccuracyChanged(Sensor sensor,int accuracy){

}

public void onSensorChanged(SensorEvent event){

    // check sensor type
    if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){

        // assign directions
        x=event.values[0];
        y=event.values[1];
        z=event.values[2];
    }
}


@Override
protected void onStart() {
    super.onStart();
    dataset.addSeries(timeSeries[0]);
    dataset.addSeries(timeSeries[1]);
    dataset.addSeries(timeSeries[2]);
    view = ChartFactory.getTimeChartView(this, dataset, renderer, "Test");
    view.refreshDrawableState();
    view.repaint();
    setContentView(view);
    mThread = new Thread(){
        public void run(){
            while(true){
            try {
                Thread.sleep(300L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
                timeSeries[0].add(new Date(), x);
                timeSeries[1].add(new Date(), y);
                timeSeries[2].add(new Date(), z);
                view.repaint();
            }
        }
    };
    mThread.start();
}

}

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:debuggable="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Activity2"
        android:label="@string/title_activity_activity2" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.test.MainActivity" />
    </activity>
</application>

</manifest>

1 个答案:

答案 0 :(得分:3)

尝试使用

  • Android工具 - &gt;修复项目属性

如果没有解决问题,请尝试

  • 项目 - &gt;清洁

我已经在我的设备上运行了您的活动,但它没有错误。