Question
Eclipse Compile Error on Javafx This is my code : package JavaFX; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.text.Font; import
Eclipse Compile Error on Javafx This is my code :
package JavaFX;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.layout.GridPane;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.control.Button;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
@SuppressWarnings("restriction")
public class CourseScore extends Application {
private static final Node btnCalculate = null;
private static final Node btnStartAgin = null;
private Label lblEarned = new Label ("Earned Score");
private Label lblMax = new Label ("Max Possible");
private Label lblScore01 = new Label ("Score 1: ");
private Label lblScore02 = new Label ("Score 2: ");
private Label lblScore03 = new Label ("Score 3: ");
private Label lblScore04 = new Label ("Score 4: ");
private Label lblScore05 = new Label ("Score 5: ");
private Label lblScore06 = new Label ("Score 6: ");
private Label lblTotal = new Label ("TOTAL: ");
private Label lblFinalEarned = new Label ("FINAL SCORE: ");
private Label lblFinalGrade = new Label ("FINAL GRADE: ");
private Label lblPerfect = new Label ("Perfect Score!");
private TextField txtEarned01 = new TextField(); private TextField txtMax01 = new TextField();
private TextField txtEarned02 = new TextField(); private TextField txtMax02 = new TextField();
private TextField txtEarned03 = new TextField(); private TextField txtMax03 = new TextField();
private TextField txtEarned04 = new TextField(); private TextField txtMax04 = new TextField();
private TextField txtEarned05 = new TextField(); private TextField txtMax05 = new TextField();
private TextField txtEarned06 = new TextField(); private TextField txtMax06 = new TextField();
private TextField txtTotalEarned = new TextField(); private TextField txtTotalMax = new TextField();
private TextField txtFinalEarned = new TextField(); private TextField txtFinalGarde = new TextField();
private Button btnClaculate = new Button("Calculate");
private Button btnStartAgagin = new Button ("Start Over");
private TextInputControl txtFinalGrade;
private Node btnStartAgain;
@Override
public void start(Stage primaryStage) {
GridPane gridP = new GridPane();
gridP.setAlignment(Pos.CENTER);
gridP.setPadding(new Insets(10, 12, 10, 12));
gridP.setHgap(14);
gridP.setVgap(16);
gridP.setStyle("-fx-background-color: HoneyDew;");
GridPane.setHalignment(lblEarned, HPos.CENTER);
GridPane.setHalignment(lblMax, HPos.CENTER);
GridPane.setHalignment(btnCalculate, HPos.RIGHT);
GridPane.setHalignment(btnStartAgin, HPos.RIGHT);
GridPane.setHalignment(lblScore01, HPos.RIGHT);
GridPane.setHalignment(lblScore02, HPos.RIGHT);
GridPane.setHalignment(lblScore03, HPos.RIGHT);
GridPane.setHalignment(lblScore04, HPos.RIGHT);
GridPane.setHalignment(lblScore05, HPos.RIGHT);
GridPane.setHalignment(lblScore06, HPos.RIGHT);
GridPane.setHalignment(lblTotal, HPos.RIGHT);
GridPane.setHalignment(lblFinalEarned, HPos.RIGHT);
GridPane.setHalignment(lblFinalGrade, HPos.RIGHT);
GridPane.setHalignment(lblPerfect, HPos.CENTER);
GridPane.setValignment(lblPerfect, VPos.TOP);
txtTotalEarned.setEditable(false); txtTotalMax.setEditable(false);
txtFinalEarned.setEditable(false); txtFinalGrade.setEditable(false);
lblTotal.setVisible(true); txtTotalEarned.setVisible(true); txtTotalMax.setVisible(true);
lblFinalEarned.setVisible(true); txtFinalEarned.setVisible(true);
lblFinalGrade.setVisible(true); txtFinalGrade.setVisible(true);
lblPerfect.setVisible(true);
lblEarned.setStyle("-fx-font-size: 15pt;");
lblMax.setStyle("-fx-font-size: 15pt;");
lblPerfect.setTextFill(Color.web("FireBrick"));
lblPerfect.setFont(Font.font("Cambria", 24));
txtFinalEarned.setStyle("-fx-background-color: #E8E8E8");
txtFinalGrade.setStyle("-fx-background-color: #E8E8E8");
txtTotalEarned.setStyle("-fx-background-color: #E8E8E8");
txtTotalMax.setStyle("-fx-background-color: #E8E8E8");
btnCalculate.setStyle("-fx-background-color: FireBrick: -fx-font-size: 12.5pt; -fx-text-fill: White; -fx-font-family: Papyrus;");
gridP.add(lblScore01, 0, 1); gridP.add(lblEarned, 1, 0); gridP.add(lblMax, 2, 0);
gridP.add(lblScore02, 0, 2); gridP.add(txtEarned01, 1, 1); gridP.add(txtMax01, 2, 1);
gridP.add(lblScore03, 0, 3); gridP.add(txtEarned02, 1, 2); gridP.add(txtMax02, 2, 2);
gridP.add(lblScore04, 0, 4); gridP.add(txtEarned03, 1, 3); gridP.add(txtMax03, 2, 3);
gridP.add(lblScore05, 0, 5); gridP.add(txtEarned04, 1, 4); gridP.add(txtMax04, 2, 4);
gridP.add(lblScore06, 0, 6); gridP.add(txtEarned05, 1, 5); gridP.add(txtMax05, 2, 5);
gridP.add(txtEarned06, 1, 6); gridP.add(txtMax06, 2, 6);
gridP.add(lblTotal, 0, 8); gridP.add(txtTotalEarned, 1, 8); gridP.add(txtTotalMax, 2, 8);
gridP.add(lblFinalEarned, 0, 9); gridP.add(txtFinalEarned, 1, 9); gridP.add(btnCalculate, 2, 11);
gridP.add(lblFinalEarned, 0, 10); gridP.add(txtFinalGrade, 1, 10); gridP.add(btnStartAgain, 2, 12);
gridP.add(lblPerfect, 1, 11);
Scene Scene2 = new Scene(gridP);
primaryStage.setScene(Scene2);
primaryStage.setTitle("Calculate Course Score");
primaryStage.setResizable(false);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
-----This is the error im getting.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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(Unknown Source)
Caused by: java.lang.NullPointerException
at javafx.scene.layout.Pane.setConstraint(Pane.java:103)
at javafx.scene.layout.GridPane.setHalignment(GridPane.java:424)
at JavaFX.CourseScore.start(CourseScore.java:62)
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 JavaFX.CourseScore
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started