Talv Class Tyler

I am in the Adnroid 2.2 SDK and cannot get my static block inside the MultiUserChat class. I tried to load it like

try { String qual = MultiUserChat.class.getName(); ClassLoader.getSystemClassLoader().loadClass(qual); } catch (ClassNotFoundException e) { e.printStackTrace(); } 

and it always gets into the catch block. 'qual' gets a real class name ... what could it be?

+4
source share
1 answer

Your application includes both wireframe classes such as ArrayList and Activity, and application classes such as FlashlightActivity. Framework classes are loaded by the system class loader (as well as the bootstrap loadeR class); application classes are loaded by the application class loader.

A system class loader can only see system classes. It does not know the path of the application class and cannot be used to load application classes. For this you need to use the application class loader. The easiest way to get the link to the application class loader is through the application class:

 try { String qual = MultiUserChat.class.getName(); MyActivity.class.getClassLoader().loadClass(qual); } catch (ClassNotFoundException e) { e.printStackTrace(); } 
+9
source

Source: https://habr.com/ru/post/1391072/


All Articles