这个问题是如此受欢迎,但是我找不到避免“ java.lang.ClassnotFoundException”的方法。
我已经实现了一种动态加载某些外部类的方法(提取战争文件后得到)
private void OnLoaded(object sender,RoutedEventArgs e)
{
var currentParent = Parent;
while (currentParent != null && !(currentParent is Window))
{
currentParent = VisualTreeHelper.GetParent(currentParent);
}
if (currentParent is Window parentWindow)
{
parentWindow.ResizeMode = ResizeMode.NoResize;
}
}
相同的异常仍然一次又一次地出现。这是堆栈跟踪:
Class<?> classGetter() {
URL url;
Class<?> cls = null;
try {
String classname=new Substringer(entireFilePath.getName(),5).output;
String classpath=new
Substringer(entireFilePath.getabsolutePath(),5+classname.length()).output;
File classDirPath = new File(classpath);
url = classDirPath.toURI().toURL();
URL[] urls = new URL[]{url};
URLClassLoader cl = new URLClassLoader(urls);
cls = cl.loadClass(packageGetter()+"."+classname);
cl.close();
} catch (ClassnotFoundException | IOException e) {
e.printStackTrace();
}
return cls;
}