I am using the following:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case EDIT_ADJUSTMENT:
if(resultCode == RESULT_OK){
try{
String adjustment = data.getStringExtra("adjustment");
adjustment = adjustment.replace(" ", "");
ClassLoader myClassLoader = ClassLoader.getSystemClassLoader();
String classNameToBeLoaded = "com.picpic.adjustments." + adjustment;
Class adjust = myClassLoader.loadClass(classNameToBeLoaded);
}catch(Exception e){
String msg = e.getMessage();
}
}
break;
}
}
When it gets to Class adjust = myClassLoader.loadClass(classNameToBeLoaded); I get the following Exception: java.lang.ClassNotFoundException: com.picpic.adjustments.ColorCorrect
The package of ColorCorrect is com.picpic.adjustments
So, Why is that error being thrown? Please let me know if you need more information. Thanks!
I am guessing this is because your class in invisible to the Class Loader through which you are trying to load the class.
I would suggest that you try this.getClass().getClassLoader() instead of ClassLoader.getSystemClassLoader().
Java has a ClassLoader Hierarchy. Each Class Loader has different class path to load classes from. Since it seems the class you are trying to load is user defined one, it may be invisible to the Class Loader returned by ClassLoader.getSystemClassLoader() method. (You can try googling for Java ClassLoader Hierarchy. May be this link is useful if you did not know about this before.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With