newInstance失败:没有<init>()</init>

时间:2011-12-29 00:16:18

标签: android

我有3个文件。一个用作数据库处理程序(插入,删除,更新等...),另一个用于维护对象构造函数及其功能。最后一个文件只是在将它们插入数据库后打印一些值。

我得到的错误是:

12-29 01:54:21.584: D/dalvikvm(574): newInstance failed: no <init>()
12-29 01:54:21.634: D/AndroidRuntime(574): Shutting down VM
12-29 01:54:21.634: W/dalvikvm(574): threadid=1: thread exiting with uncaught exception      (group=0x4001d800)
12-29 01:54:21.724: E/AndroidRuntime(574): FATAL EXCEPTION: main
12-29 01:54:21.724: E/AndroidRuntime(574): **java.lang.RuntimeException: Unable to     instantiate activity ComponentInfo**{org.teo.dbexample/org.teo.dbexample.DbexampleActivity}:     java.lang.InstantiationException: org.teo.dbexample.DbexampleActivity
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.os.Looper.loop(Looper.java:123)
12-29 01:54:21.724: E/AndroidRuntime(574):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-29 01:54:21.724: E/AndroidRuntime(574):  at java.lang.reflect.Method.invokeNative(Native Method)
12-29 01:54:21.724: E/AndroidRuntime(574):  at java.lang.reflect.Method.invoke(Method.java:521)
12-29 01:54:21.724: E/AndroidRuntime(574):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-29 01:54:21.724: E/AndroidRuntime(574):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-29 01:54:21.724: E/AndroidRuntime(574):  at dalvik.system.NativeStart.main(Native Method)
12-29 01:54:21.724: E/AndroidRuntime(574): **Caused by:**java.lang.InstantiationException: org.teo.dbexample.DbexampleActivity
12-29 01:54:21.724: E/AndroidRuntime(574):  at java.lang.Class.newInstanceImpl(Native Method)
12-29 01:54:21.724: E/AndroidRuntime(574):  at java.lang.Class.newInstance(Class.java:1429)      
12-29 01:54:21.724: E/AndroidRuntime(574):  at  android.app.Instrumentation.newActivity(Instrumentation.java:1021)   
12-29 01:54:21.724: E/AndroidRuntime(574):  at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
12-29 01:54:21.724: E/AndroidRuntime(574):  ... 11 more

构造函数:

package org.teo.dbexample;

public class Contact {

    //private variables
    int _id;
    String _name;
    String _phone_number;

    // Empty constructor
    public Contact(){

    }
    // constructor
    public Contact(int id, String name, String _phone_number){
        this._id = id;
        this._name = name;
        this._phone_number = _phone_number;
    }

    // constructor
    public Contact(String name, String _phone_number){
        this._name = name;
        this._phone_number = _phone_number;
    }

DataBase处理程序文件:

public class DbexampleActivity extends SQLiteOpenHelper {

/**
 *  Create a db with Table=Contact and Fields = id, name, phone_number
 */


// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "contactsManager";

// Contacts table name
private static final String TABLE_NAME = "contacts";

// Contacts Table Columns names
private static final String _ID = "id";
private static final String NAME = "name";
private static final String PHONE = "phone_number";


public DbexampleActivity(Context context) {                     
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

0 个答案:

没有答案