1

当我使用扩展OrmLiteBaseActivity<Database>而不是扩展时Activity ,我的logcat.

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

}
 }
4

1 回答 1

3

外部 Jar 创建名为 libs 的文件夹时出现问题,并在该文件夹中复制并粘贴所有需要的 jar 文件。工作! 这个链接有帮助

于 2012-08-21T13:08:10.067 回答