java.lang.InstantiationException:无法使用aChartEngine实例化类

时间:2014-05-20 12:14:56

标签: java android constructor achartengine

我正在尝试使用aChartEngine库(https://code.google.com/p/achartengine/)创建一个Android应用程序。

我一直在阅读很多关于“没有空构造函数”的话题,但没有解决我的问题。

点击列表项后,我正在尝试开始新的活动。

我开始这样的活动:

private void addClickList() {
        diveList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent intent = new Intent(DiveLogActi.this, DiveDetailActi.class);
                intent.putExtra(EXTRA_ID, id);  
                startActivity(intent);
            }               
        });
}

在新活动中,我有onCreate函数:

public DiveDetailActi(Bundle savedInstanceState) {
        // TODO Auto-generated constructor stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.divedetail_acti);
        Intent intent = getIntent();
        idInDb = intent.getLongExtra(DiveLogActi.EXTRA_ID, 0);                  
        getDepthGraph();
}


private void getDepthGraph()
{
    LineGraph bar = new LineGraph();
    GraphicalView gView = bar.getView(this);

    LinearLayout layout = (LinearLayout) findViewById(R.id.chartDepth);
    layout.addView(gView);
}

divedetail_acti.xml看起来像这样:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:id="@+id/diveImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="18dp"
                android:layout_marginTop="22dp"
                android:adjustViewBounds="true"
                android:maxHeight="150dp"
                android:maxWidth="150dp"
                android:src="@drawable/shark" />

            <TextView
                android:id="@+id/dateFromDb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/diveImage"
                android:layout_alignLeft="@+id/diveNumberFromDb"
                android:layout_marginBottom="20dp"
                android:text="31/12/14"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/diveNumberFromDb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/diveImage"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="22dp"
                android:layout_toRightOf="@+id/diveImage"
                android:text="Dive 1"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/placeFromDb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/diveImage"
                android:layout_below="@+id/diveImage"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:text="Ephec, Louvain-la-Neuve"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:id="@+id/chartDepth"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_alignLeft="@+id/placeFromDb"
                android:layout_below="@+id/placeFromDb"
                android:layout_marginTop="14dp" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chartTemp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_alignLeft="@+id/chartDepth"
                android:layout_below="@+id/placeFromDb"
                android:layout_marginTop="14dp" >
            </LinearLayout>

        </RelativeLayout>
    </LinearLayout>
</ScrollView>

在LineGraph中我有这个:

public class LineGraph{

    public GraphicalView getView(Context context) {

        // Our first data
        int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x values!
        int[] y =  { 30, 34, 45, 57, 77, 89, 100, 111 ,123 ,145 }; // y values!
        TimeSeries series = new TimeSeries("Line1"); 
        for( int i = 0; i < x.length; i++)
        {
            series.add(x[i], y[i]);
        }

        // Our second data
        int[] x2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x values!
        int[] y2 =  { 145, 123, 111, 100, 89, 77, 57, 45, 34, 30}; // y values!
        TimeSeries series2 = new TimeSeries("Line2"); 
        for( int i = 0; i < x2.length; i++)
        {
            series2.add(x2[i], y2[i]);
        }

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(series);
        dataset.addSeries(series2);

        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); // Holds a collection of XYSeriesRenderer and customizes the graph
        XYSeriesRenderer renderer = new XYSeriesRenderer(); // This will be used to customize line 1
        XYSeriesRenderer renderer2 = new XYSeriesRenderer(); // This will be used to customize line 2
        mRenderer.addSeriesRenderer(renderer);
        mRenderer.addSeriesRenderer(renderer2);

        // Customization time for line 1!
        renderer.setColor(Color.WHITE);
        renderer.setPointStyle(PointStyle.SQUARE);
        renderer.setFillPoints(true);
        // Customization time for line 2!
        renderer2.setColor(Color.YELLOW);
        renderer2.setPointStyle(PointStyle.DIAMOND);
        renderer2.setFillPoints(true);


        return ChartFactory.getBarChartView(context, dataset,mRenderer, Type.DEFAULT);

    }

}

我将所有必需的活动放在清单中:

<activity
    android:name="com.example.arduinodivecompanion.DiveDetailActi"
    android:label="@string/diveDetail" >
</activity>

<activity 
    android:name="org.achartengine.GraphicalActivity" >
</activity>

我还将aChartEngine.jar添加到构建路径中:

enter image description here

最后,我尝试添加一个空构造函数,但新活动只显示一个空白页。

我得到了这个输出:

05-20 17:06:11.351: E/AndroidRuntime(24830): FATAL EXCEPTION: main
05-20 17:06:11.351: E/AndroidRuntime(24830): Process: com.example.arduinodivecompanion, PID: 24830
05-20 17:06:11.351: E/AndroidRuntime(24830): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.arduinodivecompanion/com.example.arduinodivecompanion.DiveDetailActi}: java.lang.InstantiationException: can't instantiate class com.example.arduinodivecompanion.DiveDetailActi; no empty constructor
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.os.Looper.loop(Looper.java:136)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.ActivityThread.main(ActivityThread.java:5017)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at java.lang.reflect.Method.invokeNative(Native Method)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at java.lang.reflect.Method.invoke(Method.java:515)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at dalvik.system.NativeStart.main(Native Method)
05-20 17:06:11.351: E/AndroidRuntime(24830): Caused by: java.lang.InstantiationException: can't instantiate class com.example.arduinodivecompanion.DiveDetailActi; no empty constructor
05-20 17:06:11.351: E/AndroidRuntime(24830):    at java.lang.Class.newInstanceImpl(Native Method)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at java.lang.Class.newInstance(Class.java:1208)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
05-20 17:06:11.351: E/AndroidRuntime(24830):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
05-20 17:06:11.351: E/AndroidRuntime(24830):    ... 11 more
05-20 17:06:12.971: I/Adreno-EGL(24864): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
05-20 17:06:12.991: D/OpenGLRenderer(24864): Enabling debug mode 0

有人可以帮助我吗?

0 个答案:

没有答案