I am able to run the following example code
//main class
String a="Menu";
Object o = Class.forName("org.test."+a).newInstance();
//Menu class
public class Menu()
{
public Menu()
{
System.out.println("con called");
}
}
It runs fine, but when I obfuscate the code I get a no ClassNotFoundException.
I am using netbean 6.9.1 . In Additional obfusating setting i added -keepnames class org.test.Menu. But still not working. Any solution?
The trivial reason: The obfuscator changed the name of
org.test.Menuto something else (package name changed and/or class name changed). And the obfuscator can’t “refactor” the classes so that String based class names in other class files are changed too.If this is the case, tell the obfuscator not to touch the
org.testpackage (keep that name and don’t obfuscate the name of the class(es) inside).