I'm sorry if this seems trivial to you all, but I am still learning and I have looked through articles and tried several techniques...I could create each card image separately, but I need to learn how to do this. I am throwing a java.lang.NullPointerException on this bit of code:
setCardBack.setImage(new Image("image/cardDown.png"));
Now the problem is that I did fix it by entering:
setCardBack = new ImageView(new Image("image/cardDown.png"));
the problem is that when doing so I threw another NullPointerException when it tried to access that image in the loadCard method here is the part that threw the exception:
cardBack[0].setVisible(true);
Here is the full class (Btw the below code wasn't changed to reflect the above change I claimed I made so that you all can see the original unedited coded):
public class PlayerTableCardPane extends Pane {
// Data Fields
ImageView[] cardBack;
private int cardXOffset;
private int cardHeight;
private int cardCount;
// StackPane for cards
StackPane cardStack;
/** Constructor */
public PlayerTableCardPane() {
this.cardStack = new StackPane();
this.cardBack = new ImageView[5];
this.cardHeight = 50;
this.cardXOffset = 5;
this.cardCount = 0;
ImageView tempCard = null;
for (ImageView setCardBack: cardBack) {
setCardBack.setImage(new Image("image/cardDown.png"));
setCardBack.setVisible(false);
setCardBack.setFitHeight(cardHeight);
setCardBack.setPreserveRatio(true);
if (tempCard != null) {
setCardBack.setX(tempCard.getX() + cardXOffset);
}
tempCard = setCardBack;
}
getChildren().add(this.cardStack);
}
/** Constructor for setting custom height */
public PlayerTableCardPane(int cardHeight, int cardXOffset) {
this.cardStack = new StackPane();
this.cardBack = new ImageView[5];
this.cardXOffset = cardXOffset;
this.cardHeight = cardHeight;
this.cardCount = 0;
ImageView tempCard = null;
for (ImageView setCardBack: cardBack) {
setCardBack = new ImageView(new Image("image/cardDown.png"));
setCardBack.setVisible(false);
setCardBack.setFitHeight(cardHeight);
setCardBack.setPreserveRatio(true);
if (tempCard != null) {
setCardBack.setX(tempCard.getX() + cardXOffset);
}
tempCard = setCardBack;
}
getChildren().add(this.cardStack);
}
/** Get cardXOffset */
public int getCardXOffset() {
return this.cardXOffset;
}
/** Set cardXOffset */
public void setCardXOffset(int cardXOffset) {
this.cardXOffset = cardXOffset;
}
/** Get cardCount */
public int getCardCount() {
return this.cardCount;
}
/** Set cardCount */
public void setCardCount(int cardCount) {
this.cardCount = cardCount;
}
/** Load cards into StackPane */
public void loadCard() {
if (cardCount == 0) {
cardBack[0].setVisible(true);
} else if (cardCount == 1) {
cardBack[1].setVisible(true);
} else if (cardCount == 2) {
cardBack[2].setVisible(true);
} else if (cardCount == 3) {
cardBack[3].setVisible(true);
} else if (cardCount == 4) {
cardBack[4].setVisible(true);
}
this.cardCount++;
}
/** Hide last card() */
public void hideLastCard() {
if (cardCount == 4) {
cardBack[4].setVisible(false);
} else if (cardCount == 3) {
cardBack[3].setVisible(false);
} else if (cardCount == 2) {
cardBack[2].setVisible(false);
} else if (cardCount == 1) {
cardBack[1].setVisible(false);
} else if (cardCount == 0) {
cardBack[0].setVisible(false);
}
this.cardCount--;
}
/** Replace card with FaceUp Image */
public void setCardImg(ImageView card, int cardPos) {
cardBack[cardPos].setImage(card.getImage());
}
}
and here is the last exception:
java.lang.NullPointerException
at Casino_Poker.PlayerTableCardPane.loadCard(PlayerTableCardPane.java:94)
at Casino_Poker.Main.dealCards(Main.java:444)
at Casino_Poker.Main.lambda$signIn$1(Main.java:249)
at Casino_Poker.Main$$Lambda$4/86482238.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:204)
at javafx.scene.Node.fireEvent(Node.java:8175)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:204)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3746)
at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
at com.sun.glass.ui.View.handleMouseEvent(View.java:526)
at com.sun.glass.ui.View.notifyMouse(View.java:898)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:745)
Process finished with exit code 0