GraphicsEnviroment problem

So I load font with

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(getClass().getClassLoader().getResource("res/sector_017.ttf").toURI())));
font = new Font("Sector 017", Font.PLAIN, Config.get().FONT_SIZE);

and it works on eclipse’s run but not on jar, saying URI is not hierarchical. Any idea?

You can’t use “new File” to read resources out of a jar (since its not a file on the file system but actually a file inside a jar file), you need to use an inputstream.

I tried

 ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("res/sector_017.ttf")));

but it throwed

java.io.FileNotFoundException: res\sector_017.ttf (The system cannot find the path specified)

try


ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, this.getClass().getClassloader().getResourceAsStream("res/sector_017.ttf")));

Work like charm. Thanks!

GraphicsEnviroment problem solved. Now use same technique to load sounds fail :cranky:

Using Java 7?

Okay fixed all problems! thanks.

@ra4king: oh I see what you asking here. No, I compile and run with java6. My java7 is inactive in my machine. But yes, teh problem lied on AudioInputStream. Geez why jar is so complicated.