【发布时间】:2011-02-24 12:44:06
【问题描述】:
我正在开发一个尝试通过以下方式加载外部库的项目 DexClassLoader。这在 2.3 中运行良好:
public class FormularDisplayLoader {
public final static String PATH ="/data/data/at.mSystem.client/files/mSystem_Client_FormularLibrary.jar";
private DexClassLoader classLoader;
public FormularDisplayLoader(Context context){
this.context = context;
this.classLoader = new DexClassLoader("/data/data/at.mSystem.client/
files/mSystem_Client_FormularLibrary.jar",
context.getFilesDir().getAbsolutePath(),
null,
FormularDisplayLoader.class.getClassLoader());
}
public View getDisplay(String className) throws ErrorCodeException{
try {
Class c = classLoader.loadClass(className);
Method m = c.getMethod("getDisplay", Context.class);
View ret = (View) m.invoke(c.newInstance(), context);
return ret;
} catch (Exception e) {
e.printStackTrace();
throw new
ErrorCodeException(FormularErrorCode.NO_DISPLAY_AVAILABLE_FOR_FORMULAR);
}
}
}
不幸的是,在尝试将此应用程序移植到 Honeycomb 时(因为 这个应用程序的实际目标是平板电脑)DexClassLoader 会抛出一个 例外:
02-23 09:30:58.221: ERROR/dalvikvm(8022): Can't open dex cache '/data/
dalvik-cache/
data@d...@at.mSystem.client@files@mSystem_Client_FormularLibrary....@classes.dex':
No such file or directory
02-23 09:30:58.221: INFO/dalvikvm(8022): Unable to open or create
cache for /data/data/at.mSystem.client/files/
mSystem_Client_FormularLibrary.jar (/data/dalvik-cache/
data@d...@at.mSystem.client@files@mSystem_Client_FormularLibrary....@classes.dex)
02-23 09:30:58.231: WARN/System.err(8022):
java.lang.ClassNotFoundException:
at.mSystem.client.formular.contract.ContractListFormularDisplay in
loader dalvik.system.DexClassLoader@40630308
02-23 09:30:58.241: WARN/System.err(8022): at
dalvik.system.DexClassLoader.findClass(DexClassLoader.java:240)
02-23 09:30:58.241: WARN/System.err(8022): at
java.lang.ClassLoader.loadClass(ClassLoader.java:548)
02-23 09:30:58.261: WARN/System.err(8022): at
java.lang.ClassLoader.loadClass(ClassLoader.java:508)
02-23 09:30:58.261: WARN/System.err(8022): at
at.mSystem.client.system.formularmodule.formular.FormularDisplayLoader.getDisplay(FormularDisplayLoader.java:
35)
DexClassLoader 似乎忽略了第二个参数 (dexOutputDir),作为 context.getFilesDir().getAbsolutePath() 在我的例子中是“/data/data/ at.mSystem.client/files”。
您有什么解决方法的想法吗?或者这是某种 蜂窝虫?
谢谢,
罗兰
【问题讨论】:
-
我没有答案,只是想让您知道我遇到了同样的问题。
-
我在 Android 的问题跟踪器上开了一张票:code.google.com/p/android/issues/detail?id=15893
-
在您提交它的同一天,谷歌的某个人说“是的,内部错误 3439372。计划在即将发布的 Honeycomb 维护版本中发布”
标签: android android-3.0-honeycomb