2012-08-17 59 views
1

當我使用擴展OrmLiteBaseActivity<Database>,而不是擴展Activity 我獲得以下我logcat錯誤。類擴展OrmLiteBaseActivity <Database>

08-17 17:05:28.497: W/dalvikvm(8818): Unable to resolve superclass of Lcom/example/sample/MainActivity; (427) 
08-17 17:05:28.537: W/dalvikvm(8818): Link of class 'Lcom/example/sample/MainActivity;' failed 
08-17 17:05:28.537: D/AndroidRuntime(8818): Shutting down VM 
08-17 17:05:28.568: W/dalvikvm(8818): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 
08-17 17:05:28.608: E/AndroidRuntime(8818): FATAL EXCEPTION: main 
08-17 17:05:28.608: E/AndroidRuntime(8818): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.sample/com.example.sample.MainActivity}: java.lang.ClassNotFoundException: com.example.sample.MainActivity 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.ActivityThread.access$600(ActivityThread.java:123) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.os.Looper.loop(Looper.java:137) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.ActivityThread.main(ActivityThread.java:4424) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at java.lang.reflect.Method.invoke(Method.java:511) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at dalvik.system.NativeStart.main(Native Method) 
08-17 17:05:28.608: E/AndroidRuntime(8818): Caused by: java.lang.ClassNotFoundException: com.example.sample.MainActivity 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871) 
08-17 17:05:28.608: E/AndroidRuntime(8818):  ... 11 more 
08-17 17:05:28.678: I/dalvikvm(8818): threadid=3: reacting to signal 3 
08-17 17:05:28.847: I/dalvikvm(8818): Wrote stack traces to '/data/anr/traces.txt' 
08-17 17:05:29.177: I/dalvikvm(8818): threadid=3: reacting to signal 3 
08-17 17:05:29.217: I/dalvikvm(8818): Wrote stack traces to '/data/anr/traces.txt' 
08-17 17:05:29.397: I/dalvikvm(8818): threadid=3: reacting to signal 3 
08-17 17:05:29.417: I/dalvikvm(8818): Wrote stack traces to '/data/anr/traces.txt' 
08-17 17:05:30.738: I/Process(8818): Sending signal. PID: 8818 SIG: 9 

,但如果我用activity我沒有得到任何錯誤本身和應用程序運行良好 這裏是代碼爲我的主類

public class MainActivity extends OrmLiteBaseActivity<Database> { 
Button fromdatabase, fromsdcard; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    fromdatabase = (Button) findViewById(R.id.loadfromdatabase); 
    fromsdcard = (Button) findViewById(R.id.loadfromsd); 

    fromdatabase.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent in = new Intent(MainActivity.this, ListViewer.class); 
      startActivity(in); 
     } 
    }); 
    fromsdcard.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent in = new Intent(MainActivity.this, ListViewer.class); 
      startActivity(in); 
     } 
    }); 
} 
    } 

數據庫類

public class Database extends OrmLiteSqliteOpenHelper { 

private static final String DATABASE_NAME = "imagetester"; 

private static final int DATABASE_VERSION = 1; 

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

@Override 
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { 
    try { 
     Log.i(Database.class.getName(), "onCreate"); 
     TableUtils.createTable(connectionSource, image.class); 

    } catch (SQLException e) { 
     Log.e(Database.class.getName(), "Can't create database", e); 
     throw new RuntimeException(e); 
    } 
    RuntimeExceptionDao<image, Integer> dao = getSimpleDataDao(); 
    for(int i=0;i<5;i++) 
    { 
    image simple = new image(i); 
    dao.create(simple); 
    } 

} 
private RuntimeExceptionDao<image, Integer> getSimpleDataDao() { 
    return getRuntimeExceptionDao(image.class); 
} 

@Override 
public void onUpgrade(SQLiteDatabase arg0, ConnectionSource arg1, int arg2, 
     int arg3) { 
    // TODO Auto-generated method stub 

} 
} 
+1

http://stackoverflow.com/a/10046725/1289716 – MAC 2012-08-17 11:45:16

+0

你能解釋我爲什麼要擴展OrmLiteBaseActivity 。任何具體原因? – 2012-08-17 11:47:27

+0

是的,我使用ormlite所以我需要擴展ormlitebaseactivity和數據庫是我的類的名稱,我在哪裏做數據庫操作 – 2012-08-17 11:54:44

回答

3

有與外部罐子問題 創建文件夾名爲libs & 將所有需要的jar文件複製並粘貼到該文件夾​​中。 工作! this link helped