ClassNotFoundException during Dynamic Class loading in android

狂风中的少年 提交于 2019-12-13 00:41:18

问题


I am creating an app, where i am supposed to receive data through web service.

Here i am having a class, stored in the main package. I need to load data of this class dynamically i.e at run time, whenever something is received from the web service. But i am getting excepion of classNotFound.

Here is my code for dynamic loading of class,

try
{
    Class myClass = ClassLoader.getSystemClassLoader().loadClass("com.myPackage.it.ClassToLoad");
    Log.d("Dynamic class Loading", "1");
    Object DPMInstance = myClass.newInstance();
    Toast.makeText(getApplicationContext(), 
          "Get Methods" + myClass.getMethods(), 5000).show();
    Method myMethod = myClass.getMethod("sayHello", new Class[] {});      
    myMethod.invoke(DPMInstance, new Object[] { }); 
}
catch(Exception e)
{
    Log.d("Error", "" + e);
}

I am getting excpetion at this line,

Class myClass = ClassLoader.getSystemClassLoader().loadClass("com.myPackage.it.ClassToLoad");

来源:https://stackoverflow.com/questions/12420225/classnotfoundexception-during-dynamic-class-loading-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!