java - Runnable JAR file won't -


i created card game in java. it presents 1 card face , 4 more cards face down. wager 1 100 coins , try pick higher card face down cards. if pick higher card, wager doubled , can choose go double or nothing on round.

the program uses 3 .java files in 1 package:

  • highernumber: main class, contains bulk of code.
  • deck: contains definition class representing deck of cards.
  • card: contains definition class representing individual card.

so naturally, program uses lot of pictures, represent cards. in original implementation, passed imageicon string represent location of cards. like, icon face down card,

facedown = new imageicon("multimedia/redback.gif"); 

when did this, program ran when run through eclipse. used eclipse export runnable jar file. jar file ran without problem, except if moved jar file anywhere else, none of images showed up.

so researched , found out using urls combat this. reworked program use urls, have stuff this:

//set url default facedown icon. facedownurl = this.getclass().getresource(pictureroot +"redback.gif"); //set location default face of cards. facedown = new imageicon(facedownurl); 

now runs fine in eclipse, cannot exported runnable jar work. when run windows, kinda blinks , nothing. when run through command line, this:

c:\documents , settings\mstabosz>java -jar c:\temp\highernumber.jar exception in thread "main" java.lang.nullpointerexception         @ javax.swing.imageicon.<init>(unknown source)         @ highernumber.card.setimage(card.java:150)         @ highernumber.card.<init>(card.java:36)         @ highernumber.deck.<init>(deck.java:22)         @ highernumber.highernumber.<init>(highernumber.java:16)         @ highernumber.highernumber.main(highernumber.java:857) 

trying follow code, looks source of problem in card class @ line 150. @ line 150, class in setimage() function, building string called iconname used set image each card created. returns imageicon card class's constructor.

//set icon card. this.cardicon = setimage(); 

line 150 return statement. here statements create url cardiconurl used in imageicon.

//create url based on constructed string. url cardiconurl = this.getclass().getresource(iconname);  return new imageicon(cardiconurl); 

i don't what's going wrong here. program worked fine runnable jar when using strings instead of urls. works fine when run through eclipse. doesn't work runnable jar now.

i did read on called manifests, had trouble understanding. did have eclipse generate manifest program:

manifest-version: 1.0 main-class: highernumber.highernumber 

what missing?

i use like:

url myurl = this.getclass().getresource("file.png"); myiconimage = toolkit.getdefaulttoolkit().getimage(myurl); 

you're doing:

return new imageicon(cardiconurl); 

maybe try second line. store images in jar.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -