I have some problem how to initial package from class file from another directory
URL[] cp =
{
new File(file.getParent()).toURI().toURL()
};
URLClassLoader urlcl = new URLClassLoader(cp);
Class cls = urlcl.loadClass(file.getName().replaceAll("\\.class","");
if class file not contain a package, it's working.
but it's contains a package, i get some error like this :
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Waktu (wrong name: Name_pack/time/MyClass)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
I don't know how to get package.
Aucun commentaire:
Enregistrer un commentaire