前提・実現したいこと
写真をラベルに貼り付けて表示したいのですが、どうしても以下のエラーが起きてしまいます。どなたか教えて頂くことは可能でしょうか?
発生している問題・エラーメッセージ
Exception in Application start method 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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) 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.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException at saisyuukadai.five.start(five.java:25) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177) ... 1 more Exception running application saisyuukadai.five
該当のソースコード
javafx
1package saisyuukadai; 2 3import javafx.application.Application; 4import javafx.event.EventHandler; 5import javafx.scene.Scene; 6import javafx.scene.control.Button; 7import javafx.scene.control.Label; 8import javafx.scene.image.Image; 9import javafx.scene.image.ImageView; 10import javafx.scene.input.MouseEvent; 11import javafx.scene.layout.BorderPane; 12import javafx.scene.layout.HBox; 13import javafx.stage.Stage; 14 15public class five extends Application { 16 private Label lb1,lb2,lb3; 17 private Button bt1; 18 private Image im,im2; 19 public static void main(String[]args) { 20 launch(args); 21 } 22 public void start(Stage stage)throws Exception{ 23 24 im = new Image(getClass().getResourceAsStream("sizue.jpeg")); 25 lb1.setGraphic(new ImageView(im)); 26 im2 = new Image(getClass().getResourceAsStream("sizue.jpeg")); 27 lb2.setGraphic(new ImageView(im2)); 28 29 HBox hb = new HBox(10d); 30 hb.getChildren().add(lb1); 31 hb.getChildren().add(lb2); 32 33 bt1 = new Button("回答"); 34 35 BorderPane bp = new BorderPane(); 36 Scene sc = new Scene(bp,500,400); 37 38 bp.setBottom(bt1); 39 bp.setCenter(hb); 40 bp.setTop(lb3); 41 42 bt1.addEventHandler(MouseEvent.MOUSE_CLICKED, new SampleEventHandler()); 43 44 stage.setScene(sc); 45 46 stage.setTitle("間違い探しゲーム"); 47 stage.show(); 48 } 49 class SampleEventHandler implements EventHandler<MouseEvent> 50 { 51 public void handle(MouseEvent e) 52{ 53 double x = e.getX(); 54 55 double y = e.getY(); 56 57 lb3.setText(" (" + x + "," + y + ")"); 58} 59} 60}
試したこと
写真の置いてあるフォルダの場所を変更したりしてみました(binの所に写真を置くのは分かるのですが・・・)
補足情報(FW/ツールのバージョンなど)
jdk14
回答1件
あなたの回答
tips
プレビュー