java.lang.ClassNotFoundException:找不到类"com.life.Life"; [英] java.lang.ClassNotFoundException: Didn't find a class "com.life.Life"
本文介绍了java.lang.ClassNotFoundException:找不到类"com.life.Life";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图通过 DexClassLoader
从 jar文件加载类:
I was tring to load a class from a jar file through DexClassLoader
:
public class AndroidClassLoader implements ClassLoader {
private Class class1;
@Override
public Class execute(File file, String packge) {
class1 = null;
try{
DexClassLoader loader = new DexClassLoader(file.toURI().toURL().toString(), FXActivity.getInstance().getDir("outdex", 0).getAbsolutePath(), null, FXActivity.getInstance().getClassLoader());
class1 = loader.loadClass(packge);
}catch(Exception e){
e.printStackTrace();
}
return class1;
}
}
运行上述代码后,将引发错误:
After running the above code, an error will be thrown:
java.lang.ClassNotFoundException: Didn't find a class "com.life.Life"
of Path: DexPathList [[zip file "/storage/emulated/0/Life.jar"],
nativeLibraryDirectories=[/vendor/lib, /system/lib]]
jar文件的名称为 Life.jar ,其内容如下:
The name of the jar file was Life.jar and here's its content:
package com.life;
public class Life
{
public String getMessage()
{
return "Life is Beautiful!";
}
}
关于如何解决此问题的任何想法?
推荐答案
您的程序包值应为"com.life.Life"
Your package value should be "com.life.Life"
即,class1 = loader.loadClass("com.life.Life");您可以尝试一下,让我知道它对您有用吗
ie., class1 = loader.loadClass("com.life.Life"); can you try this and let me know its that working for you
这篇关于java.lang.ClassNotFoundException:找不到类"com.life.Life";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文