Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Game won't run, going crazy.  (Read 309 times)
0 Members and 1 Guest are viewing this topic.
Offline Creepy

Junior Newbie





« Posted 2014-05-11 19:09:29 »

Hey guys, been lurking for awhile but only just made an account.

Maybe it's cause it's 1am here and I should go to bed but I've been working on my first java game and it was working fine up until now.

It runs as expected in eclipse but when I export it as a runnable .jar it will start the game (load the first option box) then close, i found it to be an error loading one of the image files but what I am confused about is it was working perfectly earlier and still loads the images fine when run in eclipse yet I haven't changed any code.
The error: https://dl.dropboxusercontent.com/u/148329451/error.png

If someone could take a look at the code or try and export as a .jar and let me know if you can get it working

source: https://dl.dropboxusercontent.com/u/148329451/Shooter_1.rar

Thanks!
Offline Mr.CodeIt

Junior Member





« Reply #1 - Posted 2014-05-11 19:11:43 »

Dude I had the same problem and solved in about 2 minutes ago  Shocked. First off, are you using any libraries? (LWJGL, Slick2D, LibGDX, etc..)

I'm not drunk, I've just been up late coding.
Offline trollwarrior1
« Reply #2 - Posted 2014-05-11 19:13:27 »

input == null means that the file you're trying to load doesn't exist basically. The way to fix it is to refresh eclipse project, because eclipse only exports files that are visible in your project menu. So basically if you don't see the images from your eclipse project viewer, that means you need to refresh the project by Right Click -> Refresh or F5
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2014-05-11 19:15:58 »

Trollwarrior, while you may be right, I doubt that's the issue. The issue here is probably that OP isn't using the correct IO functions. Creepy, do you load your files using the Java class File? If so, you can't do that. There are no files in a jar, so you cannot actually create a file out of your images when you export your resources inside of your jar.

Online BurntPizza
« Reply #4 - Posted 2014-05-11 19:16:13 »

I'll bet money that you are making the same mistake everyone does:

You're using
new File("someImageInMyJar.png")
somewhere in your code.

You can't do this if the image file is in a jar file (like the jar file that also contains your code). Why? Because the jar file is actually a zip file, and the image is an entry inside of it, not a real file.

You have to use Class.getResourceAsStream() or ClassLoader.getResourceAsStream(). Google those.


EDIT: sortof ninja's by opiop. Also, troll, you're wrong. It was already working in eclipse, besides he exported it (probably) out of the workspace.
Offline trollwarrior1
« Reply #5 - Posted 2014-05-11 19:17:27 »

@opiop

input == null means the file you specified for image loading doesn't exist. Simply as that. You can work your way from there.
Online BurntPizza
« Reply #6 - Posted 2014-05-11 19:18:35 »

@opiop

input == null means the file you specified for image loading doesn't exist. Simply as that. You can work your way from there.

Indeed. It doesn't exist because the image is in the jar, not in a file. Simple as that.
Offline trollwarrior1
« Reply #7 - Posted 2014-05-11 19:24:24 »

Okay let me correct myself. ImageIO.read doesn't want files. It wants an InputStream from which it can read the data. ImageIO.read(File) is a convenience method, so you don't have to convert your file into InputStream yourself.

EDIT-
I hope I'm correct Cheesy
EDIT--
You can copy windows console output by doing this:
-> Right Click anywhere on the console
-> Mark
-> Use left mouse button to select what you want to copy
-> Right Click again will copy the information
Online BurntPizza
« Reply #8 - Posted 2014-05-11 19:42:37 »

So I looked at the source, you are using getResourceAsStream, good for you.

However your IMAGE_DIR is incorrect for the project structure. Change it to "/images/" (from "../images/") and it works.
Offline Creepy

Junior Newbie





« Reply #9 - Posted 2014-05-13 10:39:22 »

So I looked at the source, you are using getResourceAsStream, good for you.

However your IMAGE_DIR is incorrect for the project structure. Change it to "/images/" (from "../images/") and it works.

ahhh thank you! this solved the problem Smiley
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!