Click here to Skip to main content
15,885,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my program i have to change the color of a string using radio buttons and change the size of the string from the list view. I seem to be running into multiple errors in my listview code and im not sure what the problem is. I am using e(fx)clipse.

What I have tried:

package employee.view;




import javafx.beans.value.ChangeListener;
import javafx.scene.paint.Paint;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;

public class MainController {

@FXML
private BorderPane myPane;

@FXML
private RadioButton blackRadioButton;

@FXML
private ToggleGroup colorToggleGroup;

@FXML
private RadioButton redRadioButton;

@FXML
private RadioButton blueRadioButton;

@FXML
private RadioButton greenRadioButton;

@FXML
private ListView<string> mylistView;

@FXML
private CheckBox boldCheckBox;

@FXML
private CheckBox italicCheckBox;

String Text;
Text sample=new Text(50,300,"SAMPLE");
FontWeight weight = FontWeight.NORMAL; // FontWeight.BOLD is boldface
FontPosture posture = FontPosture.REGULAR; // FontPosture.ITALIC is italic
int size=18;
boolean fontBold = false;
boolean fontItalic = false;

public void initialize() {
blackRadioButton.setUserData(Color.BLACK);
redRadioButton.setUserData(Color.RED);
greenRadioButton.setUserData(Color.GREEN);
blueRadioButton.setUserData(Color.BLUE);
myPane.getChildren( ).add( sample );
sample.setFont(Font.font("Verdana", weight, posture, size));

ObservableList<string> items =FXCollections.observableArrayList (
"18", "26", "38", "56");
mylistView.setItems(items);

mylistView.getSelectionModel().selectedItemProperty().addListener(
new ChangeListener<string>() {
public void changed(ObservableValue<? extends String> ov,
String old_val, String new_val) {
size = Integer.parseInt(new_val);
sample.setFont(Font.font("Verdana", weight, posture, size));
}
});


}


@FXML
void boldCheckBoxSelected(ActionEvent event) {


}

@FXML
void colorRadioButtonSelected(ActionEvent event) {
if ((Color) colorToggleGroup.getSelectedToggle().getUserData() == Color.BLUE) {
sample.setStroke(Color.BLUE);
}

if ((Color) colorToggleGroup.getSelectedToggle().getUserData() == Color.GREEN) {
sample.setStroke(Color.GREEN);
}

if ((Color) colorToggleGroup.getSelectedToggle().getUserData() == Color.RED) {
sample.setStroke(Color.RED);
}

if ((Color) colorToggleGroup.getSelectedToggle().getUserData() == Color.BLACK) {
sample.setStroke(Color.BLACK);
}

}

@FXML
void italicCheckBoxSelected(ActionEvent event) {

}

}

Errors:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/Users/lilj9/eclipse-workspace/empl/bin/employee/view/Mainview.fxml

at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.load(Unknown Source)
at employee.Main.showMainView(Main.java:29)
at employee.Main.start(Main.java:19)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unkn own Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.reflect.Trampoline.invoke(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(Unknown Source)
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(Unknown Source)
... 14 more
Caused by: java.lang.NullPointerException
at employee.view.MainController.initialize(MainController.java:71)
... 24 more
Exception running application employee.Main
Posted
Updated 19-Nov-18 22:25pm

1 solution

Caused by: java.lang.NullPointerException
at employee.view.MainController.initialize(MainController.java:71)

Use your debugger to trap execution at or near that line and see what is causing the null pointer exception.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900