当我使用扩展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
}
}