本文介绍了类未找到在Android异常,当我使用扩展OrmLiteBaseActivity<数据库>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用扩展 OrmLiteBaseActivity<数据库>
,而不是延伸活动
我获得以下错误在我的的logcat
。
08-17 17:05:28.497:W / dalvikvm(8818):无法解析LCOM /例子/样本/ MainActivity的超类; (427)
08-17 17:05:28.537:W / dalvikvm(8818):类链接LCOM /例子/样本/ MainActivity;'失败
08-17 17:05:28.537:D / AndroidRuntime(8818):关闭VM
08-17 17:05:28.568:W / dalvikvm(8818):主题ID = 1:螺纹未捕获的异常(组= 0x409c01f8)退出
08-17 17:05:28.608:E / AndroidRuntime(8818):致命异常:主要
08-17 17:05:28.608:E / AndroidRuntime(8818):了java.lang.RuntimeException:无法实例活动ComponentInfo {com.example.sample / com.example.sample.MainActivity}:抛出java.lang.ClassNotFoundException:COM .example.sample.MainActivity
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.os.Handler.dispatchMessage(Handler.java:99)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.os.Looper.loop(Looper.java:137)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.ActivityThread.main(ActivityThread.java:4424)
08-17 17:05:28.608:E / AndroidRuntime(8818):在java.lang.reflect.Method.invokeNative(本机方法)
08-17 17:05:28.608:E / AndroidRuntime(8818):在java.lang.reflect.Method.invoke(Method.java:511)
08-17 17:05:28.608:E / AndroidRuntime(8818):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
08-17 17:05:28.608:E / AndroidRuntime(8818):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-17 17:05:28.608:E / AndroidRuntime(8818):在dalvik.system.NativeStart.main(本机方法)
08-17 17:05:28.608:E / AndroidRuntime(8818):抛出java.lang.ClassNotFoundException:产生的原因com.example.sample.MainActivity
08-17 17:05:28.608:E / AndroidRuntime(8818):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-17 17:05:28.608:E / AndroidRuntime(8818):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-17 17:05:28.608:E / AndroidRuntime(8818):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-17 17:05:28.608:E / AndroidRuntime(8818):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
08-17 17:05:28.608:E / AndroidRuntime(8818):11 ...更多
08-17 17:05:28.678的:I / dalvikvm(8818):主题ID = 3:反应以信号3
08-17 17:05:28.847:I / dalvikvm(8818):写的堆栈跟踪到/data/anr/traces.txt
08-17 17:05:29.177的:I / dalvikvm(8818):主题ID = 3:反应以信号3
08-17 17:05:29.217:I / dalvikvm(8818):写的堆栈跟踪到/data/anr/traces.txt
08-17 17:05:29.397的:I / dalvikvm(8818):主题ID = 3:反应以信号3
08-17 17:05:29.417:I / dalvikvm(8818):写的堆栈跟踪到/data/anr/traces.txt
08-17 17:05:30.738:I /流程(8818):发送信号。 PID:8818 SIG:9
但如果我用活动
我没有得到任何错误本身和应用程序运行良好
这里是code为我的主类
公共类MainActivity扩展OrmLiteBaseActivity<数据库> {
按钮fromdatabase,fromsdcard;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
fromdatabase =(按钮)findViewById(R.id.loadfromdatabase);
fromsdcard =(按钮)findViewById(R.id.loadfromsd); fromdatabase.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
在意向=新意图(MainActivity.this,ListViewer.class);
startActivity(在);
}
});
fromsdcard.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
在意向=新意图(MainActivity.this,ListViewer.class);
startActivity(在);
}
});
}
}
数据库类
公共类数据库扩展OrmLiteSqliteOpenHelper {私有静态最后弦乐DATABASE_NAME =imagetester;私有静态最终诠释DATABASE_VERSION = 1;公共数据库(上下文的背景下){
超(背景下,DATABASE_NAME,空,DATABASE_VERSION);
}@覆盖
公共无效的onCreate(SQLiteDatabase分贝,ConnectionSource connectionSource){
尝试{
Log.i(Database.class.getName(),的onCreate);
TableUtils.createTable(connectionSource,image.class); }赶上(的SQLException E){
Log.e(Database.class.getName(),无法创建数据库,E);
抛出新的RuntimeException(E);
}
RuntimeExceptionDao<图像,整型>道= getSimpleDataDao();
的for(int i = 0;我小于5;我++)
{
图像简单=新的图像(I)
dao.create(简单);
}}
私人RuntimeExceptionDao<图像,整型> getSimpleDataDao(){
返回getRuntimeExceptionDao(image.class);
}@覆盖
公共无效onUpgrade(SQLiteDatabase为arg0,ARG1 ConnectionSource,INT ARG2,
INT ARG3){
// TODO自动生成方法存根}
}
解决方案
有一个与外部JAR问题
创建文件夹命名库
&安培;
复制和粘贴文件夹中的所有需要的jar文件。
工作!
when I use extends OrmLiteBaseActivity<Database>
instead of extends Activity
I get following errors in my 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
but if I use activity
i don't get any error as such and app runs wellhere is code for my main class
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);
}
});
}
}
Database class
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
}
}
解决方案
there was problem with external Jarcreating folder named libs© and paste all needed jar files in that folder.worked!!!this link helped
这篇关于类未找到在Android异常,当我使用扩展OrmLiteBaseActivity&LT;数据库&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!