0

I am currently making a poker game in java. The model works just fine. I do however also have to make a proper view for the game. I have to use javaFX scenebuilider as well as a graphic view class with actual code. In order to do this I made a superview to include both. When i am trying to run my application I get a white window and a nullpointerexception (for the code I included).

I do not get what I am doing wrong, since no one ever explained to me the basics of Imageviews and loading images in.

I made a package "res" where I embedded all the pics that represent my cards in the deck. Also note that k.toString() automatically generates the proper name of the file including the ".png" part. I printed it out and I am sure it works!

I use the for-loop to go through my list of cards that make the deck. My cards are generated in the Class Card. So basically I am going through an ArrayList of cards.

public void initializeDeck(){
    for(Card c:model.getRound().getDeck().getList()){
        int index = model.getRound().getDeck().getList().indexOf(c);
        imv = new ImageView(new Image(getClass().getResourceAsStream("/res/"+k.toString()),95, 141, false, true));            
        deckView.add(index, imv);            
    }
    getChildren().addAll(stapelView);
}
haes
  • 11
  • 5
  • 3
    Which line gives the null pointer exception? – James_D Dec 21 '15 at 20:12
  • The stacktrace tells you exactly where it came from and descriptions of null pointers are all over. What is the problem you are having? – takendarkk Dec 21 '15 at 20:15
  • 2
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – JFPicard Dec 21 '15 at 20:28
  • 1
    Is k defined in your code? – Inge Dec 22 '15 at 05:21
  • @Inge yes it is the same as c! I am dutch so i switched everythig to english words and i forgot to switch the k, but is the same as c – haes Dec 22 '15 at 20:17
  • @James_D the new image view line! – haes Dec 22 '15 at 20:18
  • @takendarkk the error tells me i am loading in images that return a null value but i do not know why! I can open every image in netbeans properly. – haes Dec 22 '15 at 20:20
  • @takendarkk when i print out the url where he looks for my images i get a jar file with the correct map to look in! And yet it tells me that what i am looking for returns null! – haes Dec 22 '15 at 20:33
  • Use the version taking a string instead: do `URL imageURL = getClass().getResource(...);`. You can check with `System.out.println(imageURL);` and then you do `imv = new ImageView(imageURL.toExternalForm());` – James_D Dec 22 '15 at 21:18
  • @James_D thanks for reply! I do not get the error anymore! I do however only get an all white pop up window instead of my application! Any thoughts on that? Did i get the superview wrong? Or the children maybe! I dont get errors anymore so you helped me already quite a lot! Thanks – haes Dec 22 '15 at 22:26
  • @haes I did this too! https://github.com/dperezcabrera/jpoker and the (spanish) manual http://www.javahispano.org/portada/2015/2/2/nuevo-tutorial-desarrollando-con-java-8.html – David Pérez Cabrera Jan 10 '16 at 00:27
  • @DavidPérezCabrera I finished it already! the deadline was last week! Tnx though – haes Jan 10 '16 at 12:36

0 Answers0