Dalvik 类加载器之谜
我使用的是 Android 2.2 SDK,无法让 MultiUserChat 类中的静态块执行。我尝试强制加载它,因为
try
{
String qual = MultiUserChat.class.getName();
ClassLoader.getSystemClassLoader().loadClass(qual);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
它总是击中捕获块。 'qual' 获取类的有效名称...它会是什么?
I am on Android 2.2 SDK and could not get my static block inside MultiUserChat class to execute. I have tried to force load it as
try
{
String qual = MultiUserChat.class.getName();
ClassLoader.getSystemClassLoader().loadClass(qual);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
and it always hits the catch block. 'qual' gets the valid name of the class... what can it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的应用程序包括 ArrayList 和 Activity 等框架类,以及 FlashlightActivity 等应用程序类。框架类由系统类加载器(以及引导类加载器)加载;应用程序类由应用程序类加载器加载。
系统类加载器只能看到系统类。它不知道应用程序类路径,并且不能用于加载应用程序类。您需要使用应用程序类加载器来执行此操作。获取应用程序类加载器引用的最简单方法是通过应用程序类:
Your app includes both framework classes like ArrayList and Activity, plus application classes like FlashlightActivity. The framework classes are loaded by the system class loader (and also the bootstrap class loadeR); the application classes are loaded by the application class loader.
The system class loader can only see the system classes. It doesn't know the application class path and it can't be used to load application classes. You need to use the application class loader to do that. The easiest way to get a reference to the application class loader is via an application class: