public static BufferedImage[] GetAllLevels() {
URL url = LoadSave.class.getResource("/lvls");
File file = null;
try {
file = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
File[] files = file.listFiles();
File[] filesSorted = new File[files.length];
for (int i = 0; i < filesSorted.length; i++)
for (int j = 0; j < files.length; j++) {
if (files[j].getName().equals((i + 1) + ".png"))
filesSorted[i] = files[j];
}
BufferedImage[] imgs = new BufferedImage[filesSorted.length];
for (int i = 0; i < imgs.length; i++)
try {
imgs[i] = ImageIO.read(filesSorted[i]);
} catch (IOException e) {
e.printStackTrace();
}
return imgs;
}
我刚开始,所以我从某个地方取了代码,但找不到替代方法
以下是一些错误:
Exception in thread "main" java.lang.reflect. InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImp1.invoke®(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImp1. invoke (NativeMethodAccessorImp1. java:77)
at java.base/jdk.internal.reflect .DelegatingMethodAccessorImp1.invoke (DelegatingMethodAccessorImp1. java:43)
at java.base/java.lang.reflect.Method. invoke (Method. java: 568)
at org.eclipse.jdt.internal.jarinjarloader. JarRsrcLoader.main(JarRsrcLoader.java: 61)
> Caused by: java. lang. IllegalArgumentException: URI is not hierarchical
> at java.base/java.io.File.‹init›(File. java: 420)
> at utilz. LoadSave.GetAllLevels (LoadSave. java:77)
> at levels.LevelManager.buildAllLevels(LevelManager.java:41)
> at levels. LevelManager.<init›(LevelManager.java:23) at gamestates.Playing.initClasses (Playing. java: 130)
> at gamestates.Playing.<init>(Playing.java:64)
> at main.Game.initClasses(Game. java: 54) at main. Game.<init> (Game. java: 40)
> at main.MainClass.main(Mainclass.lava:6)
1条答案
按热度按时间ubof19bj1#
可以作为一种策略