Beim Versuch das Image in einer ImageView zu ändern bekomme och folgende Fehlermeldung.
Das hier ist besagte Methode, wo anscheinend der Fehler auftritt. getCard(); - Zeile h_imgView_main.setImage(img_test);
Aufgerufen wird die Methode in diser Control Klasse.
Habe nun schon das I-Net durchforstet und folgendes gefunden, als Lösung.
Habe dieses Konstrukt um angegebene Codezeile gelegt, ohne dass sich jedoch etwas geändert hätte. Verschiedene Code, aus mehreren Quellen genommen und versucht. Es hat jedoch nichts geklappt.
Habt ihr vielleicht eine Idee? Kann es möglicherweise gar nicht an der Stelle liegen?
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at at.fhj.swd2.project.berdievs14bergerru14.Hand.getCard(Hand.java:92)
at at.fhj.swd2.project.berdievs14bergerru14.Control$2.handle(Control.java:108)
at at.fhj.swd2.project.berdievs14bergerru14.Control$2.handle(Control.java:1)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$182/941730105.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at at.fhj.swd2.project.berdievs14bergerru14.Hand.getCard(Hand.java:92)
at at.fhj.swd2.project.berdievs14bergerru14.Control$2.handle(Control.java:108)
at at.fhj.swd2.project.berdievs14bergerru14.Control$2.handle(Control.java:1)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$182/941730105.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Das hier ist besagte Methode, wo anscheinend der Fehler auftritt. getCard(); - Zeile h_imgView_main.setImage(img_test);
Java:
package at.fhj.swd2.project.berdievs14bergerru14;
import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class Hand extends Container
{
private String playerCard = "";
//private String handCard;
private int sum;
private ImageView h_imgView_main = GameView.getImgView_sec();
private boolean firstTime = true; // Wenn Spieler einsteigt kriegt automatisch eine Karte
public boolean isFirstTime()
{
return firstTime;
}
public void setFirstTime(boolean firstTime)
{
this.firstTime = firstTime;
}
public String getPlayerCard()
{
return playerCard;
}
public void setPlayerCard(String playerCard)
{
this.playerCard = playerCard;
}
public int getSum()
{
return sum;
}
public void setSum(int sum)
{
this.sum = sum;
}
public Hand()
{
}
public void getCard() throws IOException
{
throwCard();
if (value == 11) // As Karte
{
if (sum >= 11)
{
value = 1; // Vorteil für den Spieler
}
}
sum = sum + value; // Summieren Kartenwertigkeit der Spieler
playerCard = element + "|" + playerCard; // Anzeige der Karten
System.out.println(playerCard);
Card.showCard(playerCard);
// Zeichnet die letzte Karte
// Paints the Card
Image img_test = new Image("style/table.jpg", true);
try {
img_test = Card.showCardImage(playerCard);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
[B]h_imgView_main.setImage(img_test);[/B]
System.out.println(sum); //TODO: Übersichtlicher! Zeigt die derzeitige Gesamtsumme an
}
}
Aufgerufen wird die Methode in diser Control Klasse.
Java:
package at.fhj.swd2.project.berdievs14bergerru14;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBException;
import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Control {
static GameControl gControl = new GameControl();
static GameView mainGui = new GameView();
static Hand player_hand = new Hand();
private static String playerCount;
public static String getPlayerCount() {
return playerCount;
}
public void startGame() throws IOException, InterruptedException, JAXBException {
Thread thread = new Thread("NEW THREAD") {
public void run() {
mainGui.startView();
}
};
thread.start();
gControl.startBj();
//mainGui.startView();
if (playerCount == null) {
playerCount = "0";
System.out.println("convert ");
}
}
List<String> testnamen = new ArrayList<String>();
private Button c_gamer_Button = GameView.getGamer_Button();
private Button c_gamer_plus = GameView.getGamer_plus();
private Button c_gamer_minus = GameView.getGamer_minus();
private Label c_top_label_gamer = GameView.getTop_label_gamer();
private Label labelUsername = PlayerView.getLabelUsername();
private Button c_button_back_main = GameView.getButton_back_main();
private Button sub_button_hit = PlayerView.getSub_button_hit();
private Button sub_button_stand = PlayerView.getSub_button_stand();
private TextField text_player_1 = GameView.getText_player_1();
private TextField text_player_2 = GameView.getText_player_2();
private TextField text_player_3 = GameView.getText_player_3();
private TextField text_player_4 = GameView.getText_player_4();
private Stage c_main_stage = GameView.getMainstage();
private Scene c_main_scene = GameView.getMain_scene();
private Scene c_sec_scene = GameView.getSec_scene();
public void GUIuserListeners()
{
sub_button_hit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent aButton) {
gControl.hit(labelUsername.getText());
sub_button_hit.disableProperty();
sub_button_hit.disabledProperty();
sub_button_hit.getScene().getWindow();
System.out.println(sub_button_hit.getScene().getWindow());
sub_button_hit.getId();
try {
[B]player_hand.getCard();[/B]
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Hit gedrückt");
}
});
sub_button_stand.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent aButton) {
System.out.println(labelUsername.getText());
//sub_button_hit.getScene().getWindow().hide();
gControl.stand(labelUsername.getText());
PauseTransition pause = new PauseTransition(Duration.seconds(1));
pause.play();
pause.stop();
sub_button_hit.getScene().getWindow();
}
});
}
public void GUI_Listeners() {
// Enter number of player
c_gamer_plus.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent AE_gamer_button) {
int i = Integer.parseInt(c_top_label_gamer.getText());
if(i<4)
{
i+=1;
toString();
c_top_label_gamer.setText(String.valueOf(i));
}
switch(i){
case 1:
text_player_2.setDisable(true);
text_player_3.setDisable(true);
text_player_4.setDisable(true);
break;
case 2:
text_player_2.setDisable(false);
text_player_3.setDisable(true);
text_player_4.setDisable(true);
break;
case 3:
text_player_2.setDisable(false);
text_player_3.setDisable(false);
text_player_4.setDisable(true);
break;
case 4:
text_player_2.setDisable(false);
text_player_3.setDisable(false);
text_player_4.setDisable(false);
break;
default:
break;
}
}
});
c_gamer_minus.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent AE_gamer_button) {
int i = Integer.parseInt(c_top_label_gamer.getText());
if(i>1)
{
i-=1;
toString();
c_top_label_gamer.setText(String.valueOf(i));
}
switch(i){
case 1:
text_player_2.setDisable(true);
text_player_3.setDisable(true);
text_player_4.setDisable(true);
break;
case 2:
text_player_2.setDisable(false);
text_player_3.setDisable(true);
text_player_4.setDisable(true);
break;
case 3:
text_player_2.setDisable(false);
text_player_3.setDisable(false);
text_player_4.setDisable(true);
break;
case 4:
text_player_2.setDisable(false);
text_player_3.setDisable(false);
text_player_4.setDisable(false);
break;
default:
break;
}
}
});
c_gamer_Button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent AE_gamer_button) {
//playerCount = GameView.getGamer_list().getSelectionModel().getSelectedItem();
playerCount = c_top_label_gamer.getText();
System.out.println("Anzahl Spieler: " + playerCount);
// for (int i =0;i < Integer.parseInt(playerCount);i++)
// {
//
// }
if (text_player_1.getText()!="")
{
testnamen.add(text_player_1.getText());
}
if (text_player_2.getText()!="")
{
testnamen.add(text_player_2.getText());
}
if (text_player_3.getText()!="")
{
testnamen.add(text_player_3.getText());
}
if (text_player_4.getText()!="")
{
testnamen.add(text_player_4.getText());
}
c_main_stage.setScene(c_sec_scene);
gControl.setPlayer(Integer.parseInt(playerCount), testnamen);
}
});
c_button_back_main.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent AE_gamer_button) {
c_main_stage.setScene(c_main_scene);
}
});
}
}
Habe nun schon das I-Net durchforstet und folgendes gefunden, als Lösung.
Java:Platform.runLater(new Runnable() { @Override public void run() { // entsprechende UI Komponente updaten } });
Habe dieses Konstrukt um angegebene Codezeile gelegt, ohne dass sich jedoch etwas geändert hätte. Verschiedene Code, aus mehreren Quellen genommen und versucht. Es hat jedoch nichts geklappt.
Habt ihr vielleicht eine Idee? Kann es möglicherweise gar nicht an der Stelle liegen?