Posted August 9, 201510 yr Hey guys, to describe my situation. I got additional data saved in the assets under assets.minigames.maps , that I need to access on server side. So i save the path of my data in the preInit Event using path = event.getSourceFile().getAbsolutePath(); The files are storing an int[][][] , saved with an ObjectOutputStream into the file. So I try to read that using the following method, where key is the name of the map (e.g. archerwars) private static int[][][] readFile(String key) { File file = new File(MiniGames.path+"/assets/minigames/maps/"+key+".fail"); try { ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); int[][][] ret = (int[][][]) in.readObject(); in.close(); return ret; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(file.getAbsolutePath()); } } In eclipse this is working just fine. But once I compile the mod it crashes the server with the following crash log [18:01:02] [server thread/INFO]: Starting minecraft server version 1.8 [18:01:02] [server console handler/ERROR]: Exception handling console input java.io.IOException: Das Handle ist ungültig //The handle is invalid (for the english ppl out there) at java.io.FileInputStream.readBytes(Native Method) ~[?:1.8.0_40] at java.io.FileInputStream.read(Unknown Source) ~[?:1.8.0_40] at java.io.BufferedInputStream.read1(Unknown Source) ~[?:1.8.0_40] at java.io.BufferedInputStream.read(Unknown Source) ~[?:1.8.0_40] at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.8.0_40] at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.8.0_40] at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.8.0_40] at java.io.InputStreamReader.read(Unknown Source) ~[?:1.8.0_40] at java.io.BufferedReader.fill(Unknown Source) ~[?:1.8.0_40] at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_40] at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_40] at net.minecraft.server.dedicated.DedicatedServer$2.run(DedicatedServer.java:97) [pq.class:?] [18:01:04] [server thread/INFO]: Loading properties [18:01:04] [server thread/INFO]: Default game type: SURVIVAL [18:01:04] [server thread/INFO]: Generating keypair [18:01:04] [server thread/INFO]: Starting Minecraft server on *:1708 [18:01:05] [server thread/ERROR]: Encountered an unexpected exception java.lang.RuntimeException: F:\Server\mods\minigames-1.8-1.0.jar\assets\minigames\maps\archer.fail at de.failender.minigames.games.MapHolder.readFile(MapHolder.java:75) ~[MapHolder.class:?] at de.failender.minigames.games.MapHolder.initialize(MapHolder.java:34) ~[MapHolder.class:?] at de.failender.minigames.MiniGames.init(MiniGames.java:66) ~[MiniGames.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40] at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537) ~[FMLModContainer.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[minecraft_server.1.8.jar:?] at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) ~[LoadController.class:?] at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190) ~[LoadController.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[minecraft_server.1.8.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[minecraft_server.1.8.jar:?] at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119) ~[LoadController.class:?] at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:731) ~[Loader.class:?] at net.minecraftforge.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:97) ~[FMLServerHandler.class:?] at net.minecraftforge.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:360) ~[FMLCommonHandler.class:?] at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:210) ~[po.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:438) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_40] [18:01:05] [server thread/ERROR]: This crash report has been saved to: F:\Server\.\crash-reports\crash-2015-08-09_18.01.05-server.txt Any ideas? Greetz Fail
August 9, 201510 yr Author I was so confused with the exception with the handler that i dont thought about the thrown ioexception Actually I dont care, because I want to crash the game anyway if there is something wrong in that part, because then my mod will be useless as fk. But yeah it is a FileNotFound exception. java.lang.RuntimeException: java.io.FileNotFoundException: F:\Server\mods\minigames-1.8-1.0.jar\assets\minigames\maps\archer.fail (Das System kann den angegebenen Pfad nicht finden) I just realized that my problem is, that my file inside a jar, so its technically not a file. So I need to read the file inside the jar. The way to do that was getClassCloader and getResourceAsStream (right?) so my problem is.. im inside a static method i cant use this.class. Whats the correct way to do that?
August 9, 201510 yr Author Was already using that, just dont realized that I need to use the relative path, seen from the jar. Thank you anyway. (So we were talking about learning java.. :'D )
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.