Eclipse でjava8の勉強をしています。以下のネットにあるコードが分かりやすいと思い
コピペして実行しようとしたら実行できません。
以下のコードで編集過程ではエラーマークは出ていないのですが、コンパイルできません。
全くどうすればいいかわからないので教えてください。
エラーは以下のような感じです。
Exception in Application start method
Exception in thread "main" 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.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 javaFX_sample.VBoxExample.start(VBoxExample.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
// VBox クラス,VBoxExample.java package javaFX_sample; import java.util.List; import com.google.common.collect.Lists; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class VBoxExample extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) throws Exception{ stage.setTitle("HBox Example"); List<Button> buttonList = Lists.newArrayList(); for (int i=0; i<5; i++) { buttonList.add(new Button(Integer.toString(i))); buttonList.get(i).setPrefWidth(80); } VBox vBox = new VBox(); vBox.setAlignment(Pos.CENTER); vBox.setPadding(new Insets(10, 10, 10, 10)); vBox.getChildren().addAll(buttonList); stage.setScene(new Scene(vBox)); stage.show(); } }



回答2件
あなたの回答
tips
プレビュー