私は学校で自分のプロジェクトのカードゲームを作っています。それは、カードがユーザに示されるGUIを使用する。JavaFXリソース入力ストリームがnullです
私は単に私はそれが現時点ではかなり見えるようにする前に作業のすべてを取得しようとしているが、カードは、それらに貼ら画像とボタンですIntelliJの
でJava FXMLを使用しています。
私はボタンに画像を取得する方法を見て、JavaFXのメインガイドは私のために働いていません。私はまた、検索しようとしたと私は1つ見つかった - Loading image resourceを - しかし、私は正確に指示に従っていると私はまだエラーを取得しています:ここで
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 48 more
Caused by: java.lang.NullPointerException: Input stream must not be null
at javafx.scene.image.Image.validateInputStream(Image.java:1128)
at javafx.scene.image.Image.<init>(Image.java:706)
at sample.Controller.cardClickHandler(Controller.java:26)
... 58 more
は、ディレクトリと私のIDEの写真です:http://imgur.com/a/B9U64
ボタンをクリックすると、画像がAce of Clubsに変更されます(取引ボタンをクリックするとすべてランダムに変更されますが、これが有効になった後に表示されます)
コードのコードは次のとおりです。
public void cardClickHandler(ActionEvent actionEvent)
{
Button button = (Button)actionEvent.getSource();
Integer row = GridPane.getRowIndex(button);
Integer column = GridPane.getColumnIndex(button);
if (row==1)
{
System.out.println("Opponent's Hand, Card "+Integer.toString(column+1));
}
if (row==3)
{
System.out.println("Your Hand, Card "+Integer.toString(column+1));
}
Image image = new Image(getClass().getResourceAsStream("/resources/images/Ace-of-Clubs.png"));
ImageView imageView = new ImageView(image);
imageView.setFitHeight(80);
imageView.setFitWidth(50);
button.setGraphic(imageView);
}
画像のURLは何ですか。それとも私はそれを間違って設定しましたか?
任意の助けもいただければ幸いです:)
ありがとう