• Post Reply Bookmark Topic Watch Topic
  • New Topic

error loading image inside jar folder  RSS feed

 
Abdelrahman Hatem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ok here is the story i wanted to make a simple TicTacToe game in java when i finished it i wanted to make the cursor an image of an 'X' or an 'O' depending who's turn is it so i downloaded to images from google images then the game worked perfectly but then i realized that i have to send the images and the jar file to anyone wants to play the game,
so i wanted to load the images from inside the jar file i googled for that so much even on http://download.oracle.com/javase/tutorial/reallybigindex.html but nothing works :'(
so i tried with my self the getResource method it didn't work with a forward slash('/') but when i put a doubled back slash('\\') it worked i was very happy and going to make a party but then i found that it only works when i run it from netbeans when i built the project and executed the jar file it didn't work i ran the jar file from cmd it told me:
input == null!
Exception in thread "main" java.lang.NullPointerException
at sun.awt.CustomCursor.<init>(Unknown Source)
at sun.awt.windows.WCustomCursor.<init>(Unknown Source)
at sun.awt.windows.WToolkit.createCustomCursor(Unknown Source)
at xo.Main.<init>(Main.java:23)
at xo.Main.main(Main.java:149)
note:
i read the packaging tutorial of oracle java se tutorial but it isn't working either.
here is the code please help:

please help,
thanks in advance.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please avoid words like craazy and multiple exclamation marks.

You would appear to have the resources file in a different structure from in NetBeans. Please check the folder structure in NetBeans and the folder structure in your application. If you use the getResource() and similar methods, they return null if the resource cannot be found. Most likely you have got the resource in a different folder structure. Do you get the Exception on the line with imgX or img0 in?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have sanitized the subject.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I have sanitized the subject.
Thank you.
 
Abdelrahman Hatem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first: sorry for using workds like craazy and multiple exclamation marks
second: i'm not sure that i know what is a structure so what is a structure

but if i know what is a structure then i am sure that the images are in the jar file i opened the jar file using winrar and i found the images in the same directory of the *.class files
i get the exception in the line of curX=tk.get...
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean in the root of the jar - or inside the xo folder ??

If the images are in the root of your jar, then call them like this: xxxx.getResource("/o.jpg"));

If the images are in the xo folder, then call them like this: xxxx.getResource("/xo/o.jpg"));
 
Abdelrahman Hatem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are in the xo folder but i tried both ways they don't work
i tried to put them in the root of the jar file but doesn't work either
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try unzipping the .jar and then you will have ordinary folders which you can explore with your usual folder exploring program. If you are on *nix, you can use the archive manager to explore the .jar.
 
Abdelrahman Hatem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why will i want to unzip the .jar file??
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abdelrahman Hatem wrote:why will i want to unzip the .jar file??

To see if the jar has the right structure - the one you expect it to have.
 
Abdelrahman Hatem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but if your read the whole thread i said that i opened the jar file with winrar and i was sure that the images are inside it.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I missed the bit about winrar.

Try executing the application on the folder structure you got from winrar, and ignore the .jar for the time being.
 
Abdelrahman Hatem
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't understand what your are saying but anyway problem solved, i used Main.class.getResource instead of getClass.getResource ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!