I'm busy with a little project to learn JavaFX.
When doing a specific action i'm getting a NullPointer and I cannot figure out why this error occurs.
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at org.hva.klm.projectagiledevelopment.MedewerkerMainController.databaseVrachtShow(MedewerkerMainController.java:308)
at org.hva.klm.projectagiledevelopment.MedewerkerMainController$1.handle(MedewerkerMainController.java:272)
at org.hva.klm.projectagiledevelopment.MedewerkerMainController$1.handle(MedewerkerMainController.java:260)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
These are the methods from the Controller class where the error occurs:
#FXML
public void zoekVracht() {
actionError.setText(" ");
try {
// Check if field is empty
if (ZoekVrachtInvoer.getText().equals("")) {
actionError.setFill(Color.FIREBRICK);
actionError.setText("Geen invoer... Probeer nogmaals.");
} else {
//database connection for first user
Statement statement = dbCon.conDatabase().createStatement();
//getting count for buttonList size
ResultSet resultCount = statement.executeQuery("SELECT COUNT(*)"
+ " from reservatie"
+ " where idReservatie like '%" + ZoekVrachtInvoer.getText() + "%'");
resultCount.next();
numberOfRows = resultCount.getInt(1);
// Select all reservations which meet the textfield characters
ResultSet rs = statement.executeQuery("SELECT * from reservatie "
+ "where idReservatie like '%"
+ ZoekVrachtInvoer.getText() + "%';"
);
// Check if any reservations exsists
if (!rs.next()) {
actionError.setFill(Color.FIREBRICK);
actionError.setText("Barcode niet gevonden");
// List all found barcodes
} else {
i = 0;
rs.beforeFirst();
buttonList = new Button[numberOfRows];
while (rs.next()) {
final int account_id = rs.getInt("idReservatie");
String username = rs.getString("Naam");
String firstname = rs.getString("gewicht");
String lastname = rs.getString("Lengte");
// int status = rs.getInt("status");
gpTable.add(new Label(username), 0, i);
gpTable.add(new Label(firstname), 1, i);
gpTable.add(new Label(lastname), 2, i);
buttonList[i] = new Button("Edit reservatie");
gpTable.add(buttonList[i], 4, i);
buttonList[i].setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
try {
Parent home_page_parent = FXMLLoader.load(FXMLDocumentController.class.getResource("FXMLInvoerVracht2.fxml"));
Scene home_page_scene = new Scene(home_page_parent);
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.hide();
app_stage.setScene(home_page_scene);
app_stage.show();
databaseVrachtShow(account_id);
System.out.println(account_id);
} catch (IOException ex) {
Logger.getLogger(MedewerkerMainController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
i++;
}
}
}
} catch (SQLException ex) {
Logger.getLogger(MedewerkerMainController.class.getName())
.log(Level.SEVERE, null, ex);
} finally {
try {
dbCon.conDatabase().close();
} catch (Exception ex) {
Logger.getLogger(MedewerkerMainController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
And
#FXML
public void databaseVrachtShow(int account_id) {
System.out.println(account_id);
try {
Statement statement = dbCon.conDatabase().createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * from reservatie "
+ "where idReservatie = " + account_id + "");
while (resultSet.next()) {
// NaamDatabase.setText(resultSet.getString("Naam"));
GewichtDatabase.setText(resultSet.getString("Gewicht"));
LengteDatabase.setText(resultSet.getString("Lengte"));
BreedteDatabase.setText(resultSet.getString("Breedte"));
HoogteDatabase.setText(resultSet.getString("Hoogte"));
//DatumDatabase.setText(resultSet.getString("Nog open"));
}
} catch (SQLException ex) {
Logger.getLogger(MedewerkerMainController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
dbCon.conDatabase().close();
} catch (Exception ex) {
Logger.getLogger(MedewerkerMainController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
The error occurs on this line: GewichtDatabase.setText(resultSet.getString("Gewicht"));
Somehow the label cannot be set to the value which should be get by the getString.
All labels got their id's etc.
As requested:"
#FXML
private Label GewichtDatabase;
#FXML
private Label LengteDatabase;
#FXML
private Label BreedteDatabase;
#FXML
private Label HoogteDatabase;
And the fxml file code:
<Label fx:id="GewichtDatabase" layoutX="526.0" layoutY="106.0" />
<Label fx:id="LengteDatabase" layoutX="526.0" layoutY="134.0" />
<Label fx:id="BreedteDatabase" layoutX="526.0" layoutY="164.0" />
<Label fx:id="HoogteDatabase" layoutX="526.0" layoutY="195.0" />
Can someone help me out?
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
So i am making this Lending Library program and everything seems to work fine except when deleting the last item in my listview, i have looked over it for about 3 hours now and cannot figure it out! for some reason it only does it when i delete that last item. please help, here is my code.
LendingLibraryGUI
import java.io.IOException;
import javafx.application.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class LendingLibraryGUI extends Application {
LendingLibrary LendingLibrary = new LendingLibrary(); //Creating an Object to access total numbers of items
MediaItems Media = new MediaItems(); // creating an array of object to access MediaItems class and allowing it to hold 100 items
private ListView<String> library = new ListView<String>(); //Creates Listview
ObservableList<String> libraryList = FXCollections.<String>observableArrayList(); //Creates a list to use in the Listview
#Override
public void start(Stage primaryStage) throws Exception {
BorderPane display = new BorderPane(); //Main display
GridPane buttons = new GridPane(); //location to display buttons
TextField outPut = new TextField(); //Text field to show inventory
Insets padding = new Insets(10); //creates Insets for padding
buttons.setPadding(padding); //padding around grid pane
buttons.setHgap(10); //Horizontal gap
libraryList = LendingLibrary.load(); //Loads contents from a txt file back into the listview
library.setItems(libraryList); //inputs list of data into the listview
for (int i =0; i !=4;i++) { //Loop to create Buttons
String[] actionButtons = {"Add","Check Out","Check In","Delete"};//String to store Button names
Button temp = new Button(actionButtons[i]); //creates a temp button
temp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); //sets the size of buttons
buttons.add(temp, i, 0); //add buttons to grid pane
GridPane.setHgrow(temp, Priority.ALWAYS);
GridPane.setVgrow(temp, Priority.ALWAYS);
if (temp.getText().equals("Add")) { //if add button is pushed
temp.setOnAction((e) -> {
try {
add();
} catch (IOException e1) {
e1.printStackTrace();
}
});
}
else if (temp.getText().equals("Delete")) { //if delete button is pushed
library.getSelectionModel().selectedItemProperty().addListener(ov -> { //gets the selected item from the listview
temp.setOnAction((e) -> {
if(libraryList.isEmpty()) {
}
else {
try {
deleteLibrary();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
});
}
else if (temp.getText().equals("Check Out")){ //if check out button is pushed
library.getSelectionModel().selectedItemProperty().addListener(ov -> { //gets the selected item from the listview
String name = library.getSelectionModel().getSelectedItem().toString(); //stores selected listview data into a string
temp.setOnAction((e) -> { { // when checkout button is pushed
if (name.contains(" is currently on loaned to ")) {
errorMessage("Currently on Loan");
}
else {
inputGUI("Who did you loan this to?");
}
}
});
});
}
else if (temp.getText().equals("Check In")) {
library.getSelectionModel().selectedItemProperty().addListener(ov -> { //gets the selected item from the listview
String name = library.getSelectionModel().getSelectedItem().toString(); //stores selected listview data into a string
temp.setOnAction((e) -> { { // when checkout button is pushed
if (!name.contains(" is currently on loaned to ")) { //Catch if the item is not on loan
errorMessage("Not on Loan");
}
else {
try {
checkIn();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
});
}
}
outPut.setEditable(false); //no editing
outPut.setFont(Font.font("monospace", FontWeight.BOLD, 20)); //sets fonts
outPut.setMinHeight(300);//sets minimum height
display.setTop(library); //sets output in display on top
display.setCenter(buttons); //sets buttons on center
Scene scene = new Scene(display); //creates new scene
primaryStage.setTitle("Lending Library"); //sets title of GUI
primaryStage.setScene(scene); //adds scene to GUI
primaryStage.setMinHeight(500); //Minimum height
primaryStage.setMinWidth(400);//Minimum Width
primaryStage.show();//Displays GUI to user
}
public static void main(String[] args) {
launch(args);
}
private void add() throws IOException { //adding items to the library
inputGUI("Title:"); //input method
try {
LendingLibrary.Save(library); //updates save of media
} catch (IOException e1) {
e1.printStackTrace();
}
}
private void inputGUI(String input) { //input method to put information into the list
Stage secondaryStage = new Stage();
BorderPane border = new BorderPane();
VBox titlePane = new VBox(8);
HBox buttonLayout = new HBox(8);
Label lblTitle = new Label(input);
Button save = new Button("Save");
Button close = new Button("Close");
Insets padding = new Insets(10);
TextField txt = new TextField("");
close.setOnAction((e) -> secondaryStage.close());; //close button closes secondary stage
save.setOnAction(new EventHandler<ActionEvent>() { //Save button to save information
#Override
public void handle(ActionEvent e) {
if (txt.getText().trim().isEmpty()) { //if text field is empty do nothing
errorMessage("Please Enter Data into the text area"); //tells user to enter data in text field
}
else {
if (input.equals("Title:")) { //gets the title of media
Media.setTitle(txt.getText()); //sets title of media
secondaryStage.close();
inputGUI("Format:"); //calls inputGUI to get format of media
}
else if (input.equals("Format:")) { //gets the format of media
Media.setFormat(txt.getText()); //sets format of media
secondaryStage.close();
addToLibrary(); //adds media to library
}
else if (input.equals("Who did you loan this to?")) { //gets information on who borrowed the media
Media.setLoan(txt.getText()); //sets loaned out
secondaryStage.close();
inputGUI("When did you loan it(date)?"); //gets date when media was borrowed
}
else if (input.equals("When did you loan it(date)?")) { //gets date when media was borrowed
Media.setDate(txt.getText());//sets date when media was borrowed
secondaryStage.close();
checkOut(); //checks out media from library
}
}
try {
LendingLibrary.Save(library); //updates save of media
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
buttonLayout.getChildren().addAll(close,save);
titlePane.setPadding(padding);
titlePane.getChildren().addAll(lblTitle,txt,buttonLayout);
border.setCenter(titlePane);
BorderPane.setAlignment(titlePane, Pos.CENTER);
Scene scene = new Scene(border); //creates new scene
secondaryStage.setTitle("Input"); //sets title of GUI
secondaryStage.setScene(scene); //adds scene to GUI
secondaryStage.setMinHeight(200); //Minimum height
secondaryStage.setMinWidth(350);//Minimum Width
secondaryStage.setMaxHeight(200); //Minimum height
secondaryStage.setMaxWidth(350);//Minimum Width
secondaryStage.show();//Displays GUI to user
}
private void addToLibrary() { //adding media to library
String total; //string to hold name and format of media
total = Media.getTitle();
total = total + " ("+ Media.getFormat() +")";
libraryList.add(total); //adds media to list
library.setItems(libraryList); //adds list to library
}
private void deleteLibrary() throws IOException { //deletes media from library
int selectedItem = library.getSelectionModel().getSelectedIndex(); //gets selected item in library list
libraryList.remove(selectedItem); //removes media from list
LendingLibrary.Save(library); //updates save of media
}
private void checkOut(){ //checkout method for media
String name = library.getSelectionModel().getSelectedItem().toString(); //grabs name of media selected
int selectedItem = library.getSelectionModel().getSelectedIndex(); //grabs location of media in list
libraryList.remove(selectedItem); //removes selected media
libraryList.add(name + " | is currently on loaned to " + Media.getLoan() + " on " + Media.getDate()); //add media back to list
}
private void checkIn() throws IOException { //check in method for media
String temp = library.getSelectionModel().getSelectedItem().toString(); //grabs name of media selected
String data = temp.substring(temp.indexOf("|") -1); //splits data up
temp = temp.replace(data, ""); //removes checked out
int selectedItem = library.getSelectionModel().getSelectedIndex(); //grabs location of media
libraryList.remove(selectedItem); //removes media
libraryList.add(temp); //adds data back in
try {
LendingLibrary.Save(library); //updates save of media
} catch (IOException e1) {
e1.printStackTrace();
}
}
private void errorMessage(String message) { //displays error messages
Stage errorStage = new Stage();
BorderPane border = new BorderPane();
VBox titlePane = new VBox(8);
HBox buttonLayout = new HBox(8);
Label lblTitle = new Label(message); //displays reason of error
Button close = new Button("Close");
Insets padding = new Insets(10);
close.setOnAction((e) -> errorStage.close());;
buttonLayout.getChildren().addAll(close);
buttonLayout.setAlignment(Pos.CENTER);
titlePane.setPadding(padding);
titlePane.getChildren().addAll(lblTitle,buttonLayout);
titlePane.setAlignment(Pos.CENTER);
border.setCenter(titlePane);
BorderPane.setAlignment(titlePane, Pos.CENTER);
Scene scene = new Scene(border); //creates new scene
errorStage.setTitle("Error"); //sets title of GUI
errorStage.setScene(scene); //adds scene to GUI
errorStage.setMinHeight(200); //Minimum height
errorStage.setMinWidth(350);//Minimum Width
errorStage.setMaxHeight(200); //Minimum height
errorStage.setMaxWidth(350);//Minimum Width
errorStage.show();//Displays GUI to user
}
}
LendingLibrary
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;
public class LendingLibrary{
public void Save(ListView<String> library) throws IOException { //saves library as text file
String joined = library.getItems().stream()
.map(Object::toString)
.collect(Collectors.joining(", "));
File file = new File("LendingLibrary.txt");//Creates the text file Calc
file.createNewFile(); //if file doesnt exist it will create it (if it does nothing will happen)
if(file.exists()) { //if the file exists
PrintWriter output = new PrintWriter(file);
output.println(joined);
if(!file.exists()) { //if file doesn't exist
System.out.println("Error creating file");
}
output.close();
}
}
#SuppressWarnings("resource")
public ObservableList<String> load() throws FileNotFoundException { //loads information into program
ObservableList<String> libraryList = FXCollections.<String>observableArrayList(); //creates a list
File file = new File ("LendingLibrary.txt"); //access the file
if(file.exists()) { //if file does exist
Scanner input = new Scanner(file);
input.useDelimiter(","); //Separates data by a comma
while (input.hasNext()) { //while the list has data
String temp = input.next(); //stores data into a string
temp = temp.trim(); //trims spaces from beginning of data
if (temp.equals("")) {
}
else {
libraryList.addAll(temp); //stores data into the list
}
}
}
else if(!file.exists()) { //if does not file exist
}
return libraryList; //returns list to use in the listview
}
}
MediaItems
public class MediaItems {
private String title;
private String format;
private String loanedTo;
private String dateLoaned;
public void setTitle(String name) {title = name;}
public void setFormat(String type) {format = type;}
public String getTitle() {return title;}
public String getFormat() {return format;}
public void setLoan(String loaned) {loanedTo = loaned;}
public String getLoan() {return loanedTo; }
public void setDate(String date) {dateLoaned = date;}
public String getDate() {return dateLoaned;}
}
Not sure if it matters but here is the exception it throws, it doesnt actually crash the program or anything just an error it throws when i delete the last item...
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at LendingLibraryGUI.lambda$3(LendingLibraryGUI.java:85)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102)
at javafx.scene.control.MultipleSelectionModelBase.lambda$new$34(MultipleSelectionModelBase.java:67)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:72)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:147)
at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68)
at javafx.scene.control.MultipleSelectionModelBase.clearSelection(MultipleSelectionModelBase.java:682)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel$2.onChanged(ListView.java:1222)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
at LendingLibraryGUI.deleteLibrary(LendingLibraryGUI.java:266)
at LendingLibraryGUI.lambda$2(LendingLibraryGUI.java:72)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at LendingLibraryGUI.lambda$5(LendingLibraryGUI.java:107)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102)
at javafx.scene.control.MultipleSelectionModelBase.lambda$new$34(MultipleSelectionModelBase.java:67)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:72)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:147)
at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68)
at javafx.scene.control.MultipleSelectionModelBase.clearSelection(MultipleSelectionModelBase.java:682)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel$2.onChanged(ListView.java:1222)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
at LendingLibraryGUI.deleteLibrary(LendingLibraryGUI.java:266)
at LendingLibraryGUI.lambda$2(LendingLibraryGUI.java:72)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Any Help would be greatly appreciated!! Thanks in advance!
Change:
String name = library.getSelectionModel().getSelectedItem().toString();
To:
String name = library.getSelectionModel().getSelectedItem();
library.getSelectionModel().getSelectedItem() is null -- i.e. you are dereferencing a null pointer!
// So apparently it seems to save it but it does no show it in the table or even in the pane
package library.application.main.lmember;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import library.application.main.member.AddMemberController;
import library.application.database.Database;
public class LMemberController implements Initializable {
ObservableList<Member> list = FXCollections.observableArrayList();
#FXML
private AnchorPane anchorPane;
#FXML
private TableView<Member> tableView;
#FXML
private TableColumn<Member, String> nameCol;
#FXML
private TableColumn<Member, String> idCol;
#FXML
private TableColumn<Member, String> mobileCol;
#FXML
private TableColumn<Member, String> emailCol;
#Override
public void initialize(URL url, ResourceBundle rb) {
loadData();
initCol();
}
private void initCol(){
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
mobileCol.setCellValueFactory(new PropertyValueFactory<>("mobile"));
emailCol.setCellValueFactory(new PropertyValueFactory<>("email"));
}
private void loadData() {
Database handel = Database.getInstance();
String qu = "SELECT * FROM MEMBER";
ResultSet rs = handel.execQuery(qu);
try {
while (rs.next()) {
String name = rs.getString("name");
String mobile = rs.getString("mobile");
String id = rs.getString("id");
String email = rs.getString("email");
list.addAll(new Member(name, id, mobile, email));
}
} catch (SQLException ex) {
Logger.getLogger(AddMemberController.class.getName()).log(Level.SEVERE, null, ex);
}
tableView.setItems(list);
}
public static class Member
{
private final SimpleStringProperty name;
private final SimpleStringProperty id;
private final SimpleStringProperty mobile;
private final SimpleStringProperty email;
public Member(String Nmame, String id, String mobil, String email)
{
this.name = new SimpleStringProperty(Nmame);
this.id = new SimpleStringProperty(id);
this.mobile = new SimpleStringProperty(mobil);
this.email = new SimpleStringProperty(email);
}
public String getName()
{
return name.get();
}
public String getId()
{
return id.get();
}
public String getMobile()
{
return mobile.get();
}
public String getEmail()
{
return email.get();
}
}
}
// And this is the error that keeps popping up Even tho i defined the mobile column it is still not working.
Table MEMBER already exists. Ready for go!
Apr 04, 2018 12:47:01 PM library.application.main.lmember.LMemberController loadData
SEVERE: null
java.sql.SQLException: Column 'mobile' not found.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedResultSet.findColumnName(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
at library.application.main.lmember.LMemberController.loadData(LMemberController.java:72)
at library.application.main.lmember.LMemberController.initialize(LMemberController.java:52)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at library.application.main.window.MainWindowController.loadWindow(MainWindowController.java:87)
at library.application.main.window.MainWindowController.loadMTable(MainWindowController.java:76)
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)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:748)
Caused by: ERROR S0022: Column 'mobile' not found.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 78 more
// this is my database
package library.application.database;
import javax.swing.;
import java.sql.;
public final class Database {
private static Database handel = null ;
private static final String DB_URL = "jdbc:derby:database;create=true";
private static Connection conn = null;
private static Statement stmt = null;
private Database() {
createConnection();
setupBookTable();
setupMemberTable();
}
public static Database getInstance() {
if (handel== null) {
handel = new Database();
}
return handel;
}
void createConnection() {
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
conn = DriverManager.getConnection(DB_URL);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Cant load database", "Database Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
void setupBookTable() {
String TABLE_NAME = "BOOK";
try {
stmt = conn.createStatement();
DatabaseMetaData dbm = conn.getMetaData();
ResultSet tables = dbm.getTables(null, null, TABLE_NAME.toUpperCase(), null);
if (tables.next()) {
System.out.println("Table " + TABLE_NAME + " already exists. Ready for go!");
} else {
stmt.execute("CREATE TABLE " + TABLE_NAME + "("
+ " id VARCHAR (200) primary key,\n"
+ " title VARCHAR(200),\n"
+ " author VARCHAR(200),\n"
+ " publiser VARCHAR(100),\n"
+ " isAvail boolean default true"
+ " )");
}
} catch (SQLException e) {
System.err.println(e.getMessage() + " --- setupDatabase");
} finally {
}
}
void setupMemberTable() {
String TABLE_NAME = "MEMBER";
try {
stmt = conn.createStatement();
DatabaseMetaData dbm = conn.getMetaData();
ResultSet tables = dbm.getTables(null, null, TABLE_NAME.toUpperCase(), null);
if (tables.next()) {
System.out.println("Table " + TABLE_NAME + " already exists. Ready for go!");
} else {
stmt.execute("CREATE TABLE " + TABLE_NAME + "("
+ " id VARCHAR(10) primary key,\n"
+ " name VARCHAR(15),\n"
+ " mobile VARCHAR(12),\n"
+ " email VARCHAR(100)\n"
+ " )");
}
} catch (SQLException e) {
System.err.println(e.getMessage() + " --- setupDatabase");
} finally {
}
}
public ResultSet execQuery(String query) {
ResultSet result;
try {
stmt = conn.createStatement();
result = stmt.executeQuery(query);
} catch (SQLException ex) {
System.out.println("Exception at execQuery: data " + ex.getLocalizedMessage());
return null;
} finally {
}
return result;
}
public boolean execAction(String qu) {
try {
stmt = conn.createStatement();
stmt.execute(qu);
return true;
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error:" + ex.getMessage(), "Error Occured", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception at execQuery: data " + ex.getLocalizedMessage());
return false;
} finally {
}
}
}
Update your method where you are providing DDL statement to fix the error.
method:
void setupMemberTable() {
String TABLE_NAME = "MEMBER";
try {
stmt = conn.createStatement();
DatabaseMetaData dbm = conn.getMetaData();
ResultSet tabless = dbm.getTables(null, null, TABLE_NAME.toUpperCase(), null);
if (tabless.next()) {
System.out.println("Table " + TABLE_NAME + " already exists. Ready for go!");
} else {
stmt.execute("CREATE TABLE " + TABLE_NAME + "("
+ " id VARCHAR(10) primary key,\n"
+ " COLUMN_NAME VARCHAR(15),\n"
+ " mobile VARCHAR(12),\n"
+ " email VARCHAR(100)\n"
+ " )");
}
} catch (SQLException e) {
System.err.println(e.getMessage() + " --- setupDatabase");
} finally {
}
}
You have used 'name' as column name which is reserved keyword.
For your reference-
https://dev.mysql.com/doc/refman/5.5/en/keywords.html
OR
Just put
DROP TABLE IF EXISTS tablename; before your CREATE TABLE statement.
While I want do two methods in a row it gave me a SQLException. The one that throw me the exception is goNext().
I did verifyID() and then goNext()
The redline is I wanna SELECT from database and make a new record from the selected data.
private void verifyID() {
nameTxtFld.setDisable(false);
instNameTxtFld.setDisable(false);
addTxtArea.setDisable(false);
nextButton.setDisable(false);
KonekDB.createConnection();
try {
String sql = "SELECT * FROM privateguest WHERE idNumber='" + idNumTxtFld.getText() + "' AND idType= '" + idType.getSelectionModel().getSelectedIndex() + "'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
if (rs.next()) {
String NM = rs.getString("name");
nameTxtFld.setText(NM);
String INS = rs.getString("institution");
instNameTxtFld.setText(INS);
String ADD = rs.getString("address");
addTxtArea.setText(ADD);
}
} catch (SQLException ex) {
System.out.println("SQL Exception (verify)");
}
KonekDB.closeConnection();
}
private void goNext() {
if (nameTxtFld.getText() == null || nameTxtFld.getText().trim().isEmpty()
|| instNameTxtFld.getText() == null || instNameTxtFld.getText().trim().isEmpty()
|| addTxtArea.getText() == null || addTxtArea.getText().trim().isEmpty()) {
alertDialog.showAndWait();
} else {
String satu = idNumTxtFld.getText();
String dua = nameTxtFld.getText();
String tiga = addTxtArea.getText();
String empat = instNameTxtFld.getText();
int delapan = idType.getSelectionModel().getSelectedIndex();
String sembilan = timeStamp.getText();
try {
KonekDB.createConnection();
String sql = "INSERT INTO privateguest"
+ "(idNumber, name, address, institution, idType, startTime) "
+ "VALUES "
+ "('" + satu + "','" + dua + "','" + tiga + "','" + empat + "','" + delapan + "','" + sembilan + "')";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
if (rs.next()) {
Frame1 frame1 = new Frame1(english);
this.getScene().setRoot(frame1);
}
} catch (SQLException ex) {
System.out.println("SQL Exception (next)");
}
Frame3Private frame3 = new Frame3Private(english);
this.getScene().setRoot(frame3);
}
}
And here is my Database Connection class
package ClientSide;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class KonekDB {
private static String path = null;
private static String url_db = null;
private static String username = null;
private static String password = null;
public static Connection conn = null;
public static Connection createConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
path = "localhost/admtamudki";
url_db = "jdbc:mysql://" + path;
username = "root";
password = "";
conn = DriverManager.getConnection(url_db, username, password);
System.out.println("Koneksi Database Sukses");
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException<Wanna Create>");
System.exit(0);
} catch (SQLException e) {
System.out.println("SQLException<Wanna Create>");
System.exit(0);
}
return conn;
}
public static Connection getConnection() {
return conn;
}
public static void closeConnection() {
try {
conn.close();
System.out.println("Database closed");
} catch (SQLException e) {
System.out.println("SQLException<Wanna Close>");
System.exit(0);
}
}
}
Here is the stack trace. I just found it by doing printStackTrace.
java.sql.SQLException: Field 'targetedDiv' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1541)
at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2605)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1469)
at ClientSide.Frame2Private.goNext(Frame2Private.java:349)
at ClientSide.Frame2Private.lambda$EventHandler$3(Frame2Private.java:401)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
FYI: The SQL String run well if I execute it directly in PHPMyAdmin DBMS SQL menu.
ALHAMDULILLAH
It's 10 pm and finally i found the the problems to solve. The problem is I FORGOT TO SET THE DEFAULT VALUE of my fields in PHPMyAdmin.
Case closed, thanks for your attention. Have a tight sleep.
I Have this code, It uses JavaFX Controls, the Code "fi.setOnAction(e -> fi.setStyle("-fx-background-color: #00C275;"));" is supposed to Change the Color of the Button fi, But Doesn't work(Throws Exception), but Interestingly it works after All other Code except for button and the setOnAction is removed :
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleStringProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Control;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.control.*;
public class Medow extends Application {
public static void main(String arg[]) {
launch(arg);
}
public void start(Stage primarystage) {
primarystage.setTitle("Medow");
primarystage.setResizable(false);
// Label l = new Label("Hello");
// setXY( 0, 0, l);
Image image = new Image("/modified/user.jpg");
ImageView iv1 = new ImageView();
iv1.setImage(image);
iv1.setFitWidth(93.75);
iv1.setPreserveRatio(true);
//iv1.setX(75);
//iv1.setY(75);
Circle c = new Circle(46.875, 46.875, 46.875, Color.BLUE); // Previously it was 75, 75 - after adding image the Circle Moves Down, and changing it to 93.75/2 = 46.875 fixes this.
iv1.setClip(c);
VBox v1 = new VBox(iv1); // Upper Left VBox - inside vb
v1.setMinHeight(170);
v1.setPadding(new Insets(28.125, 0, 0, 28.125));
Label fa = new Label("Farming");
fa.setStyle("-fx-text-fill: #969696; -fx-font-weight: bold;");
fa.setPadding(new Insets(5, 0, 10, 10));
//fi.setStyle("-fx-background-color: #606365; -fx-text-fill: #ffffff; -fx-font-weight: bold;");
ImageView fiv = new ImageView(new Image("/modified/map.png"));
fiv.setFitHeight(20);
fiv.setPreserveRatio(true);
Button fi = new Button("Farm", fiv); // Farm Button
fi.setPadding(new Insets(7.5, 65, 7.5, 20)); // It would be more Efficient to use HBox inside Button
fi.setGraphicTextGap(10);
ImageView crv = new ImageView(new Image("/modified/crop.png"));
crv.setFitHeight(20);
crv.setPreserveRatio(true);
Button cr = new Button( "Crop", crv); // Crop Button
cr.setGraphicTextGap(10);
cr.setPadding(new Insets(7.5, 67, 7.5, 20));
ImageView rfv = new ImageView(new Image("/modified/rain.png"));
rfv.setFitHeight(20);
rfv.setPreserveRatio(true);
Button rf = new Button("Rainfall", rfv); // Rainfall Button
rf.setPadding(new Insets(7.5, 50, 7.5, 20));
rf.setGraphicTextGap(10);
ImageView mov = new ImageView(new Image("/modified/drop.png"));
mov.setFitHeight(20);
mov.setPreserveRatio(true);
Button mo = new Button("Moisture", mov); // Moisture
mo.setPadding(new Insets(7.5, 40, 7.5, 20));
mo.setGraphicTextGap(10);
ImageView evv = new ImageView(new Image("/modified/cal.png"));
evv.setFitHeight(20);
evv.setPreserveRatio(true);
Button ev = new Button("Events", evv); //Events
ev.setPadding(new Insets( 7.5, 55, 7.5, 20));
ev.setGraphicTextGap(10);
cr.setId("lp");
rf.setId("lp");
mo.setId("lp");
ev.setId("lp");
fi.setId("lp");
changeBackgroundOnHoverUsingBinding(cr);
changeBackgroundOnHoverUsingBinding(rf);
changeBackgroundOnHoverUsingBinding(mo);
changeBackgroundOnHoverUsingBinding(ev);
changeBackgroundOnHoverUsingBinding(fi);
/* fi.setOnMouseClicked(new EventHandler<MouseEvent>() {
fi.setStyle("")
}); */
fi.setOnAction(e -> fi.setStyle("-fx-background-color: #00C275;"));
/*
changeBackgroundOnClickUsingBinding(fi);
changeBackgroundOnClickUsingBinding(cr);
changeBackgroundOnClickUsingBinding(mo);
changeBackgroundOnClickUsingBinding(ev);
changeBackgroundOnClickUsingBinding(rf);
*/
VBox v2 = new VBox( fa, fi, cr, rf, mo, ev); // Lower Left VBox - inside vb
v2.setPadding(new Insets( 0, 0, 0, 0));
VBox vb = new VBox(v1, v2); // Left Outer Most VBox
vb.setMaxWidth(150);
vb.setMinWidth(150);
vb.setStyle("-fx-background-color: #454851;");
BorderPane bp = new BorderPane();
bp.setLeft(vb);
Scene sc = new Scene(bp, 800, 500);
sc.getStylesheets().add(Medow.class.getResource("all.css").toExternalForm()); // Adding all.css
primarystage.setScene(sc);
primarystage.show();
}
public void setXY(double x, double y, Control o){
o.setLayoutX(x);
o.setLayoutY(y);
}
/* public void butStyle(Control... b1){
for(Control b : b1){
//b.setStyle("-fx-background-color: :#606365;");
}
} */
private void changeBackgroundOnHoverUsingBinding(Node node) { // Function To Change Button Color on Hover
node.styleProperty().bind(
Bindings
.when(node.hoverProperty())
.then(
new SimpleStringProperty("-fx-background-color: #373940;")
)
.otherwise(
new SimpleStringProperty("-fx-background-color: #454851;")
)
);
}
}
Here is the Exception it is Throwing :
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Button.style : A bound value cannot be set.
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:140)
at javafx.scene.Node$4.set(Node.java:1101)
at javafx.scene.Node$4.set(Node.java:1095)
at javafx.scene.Node.setStyle(Node.java:1073)
at Medow$1.handle(Medow.java:121)
at Medow$1.handle(Medow.java:116)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Button.style : A bound value cannot be set.
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:140)
at javafx.scene.Node$4.set(Node.java:1101)
at javafx.scene.Node$4.set(Node.java:1095)
at javafx.scene.Node.setStyle(Node.java:1073)
at Medow$1.handle(Medow.java:121)
at Medow$1.handle(Medow.java:116)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
Process finished with exit code 0
The stack trace tells you the problem:
Button.style : A bound value cannot be set.
i.e. you have bound the style property with
node.styleProperty().bind(...
and then you try to call
fi.setStyle("-fx-background-color: #00C275;")
To fix this, you either need to unbind the style property before setting it in the handler (in which case it will no longer change color when the mouse hovers/unhovers over it), or your binding needs to accommodate the logic of having been pressed. Which approach you use depends on what functionality you want.
I had the period webservice originally tomcat server.
Now I want to segment webservice transplant to GAE.
I transplant was successful.
Implementation, but this error message is displayed.
Will this cause the possibility of error?
MY CODE:
public class LOAD extends HttpServlet{
static String JBx;
static String JBy;
static String JBSx;
static String JBSy;
static String gps;
String a;
int i;
private Connection con = null; //Database objects
private Statement stat = null;
private ResultSet rs = null;
private PreparedStatement pst = null;
private String dropdbSQL = "DROP TABLE User ";
private String createdbSQL = "CREATE TABLE User (" +
" id INTEGER " +
" , name VARCHAR(20) " +
" , passwd VARCHAR(20))";
private String insertdbSQL = "insert into User(id,gps,recopy) " +
"select ifNULL(max(id),0)+1,?,? FROM User";
private String selectSQL = "select * from User ";
public static void main(String[] args)
{
}
public void SelectTable()
{
try
{
stat = con.createStatement();
rs = stat.executeQuery(selectSQL);
while(rs.next())
{
JBSx =rs.getString("gps");
JBSx="<div id=dd>"+JBSx+"</div>";
if(JBx!=null){
JBx=JBx+JBSx;
}else
{
JBx=JBSx;
}
JBSy =rs.getString("recopy");
JBSy="<div id=ff>"+JBSy+"</div>";
if(JBy!=null){
JBy=JBy+JBSy;
}
else
{
JBy=JBSy;
}
}
}
catch(SQLException e)
{
System.out.println("DropDB Exception :" + e.toString());
}
// finally
// {
// Close();
// }
}
private void Close()
{
try
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(stat!=null)
{
stat.close();
stat = null;
}
if(pst!=null)
{
pst.close();
pst = null;
}
}
catch(SQLException e)
{
System.out.println("Close Exception :" + e.toString());
}
}
public LOAD()
{
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://hl2dm.synology.me:3306/teama",
"abc","");
}
catch(ClassNotFoundException e)
{
System.out.println("DriverClassNotFound :"+e.toString());
}
catch(SQLException x) {
System.out.println("Exception :"+x.toString());
}
}
public void doGet(HttpServletRequest rq, HttpServletResponse rp)
throws ServletException, IOException{
JBx=null;
JBy=null;
JBSx=null;
JBSy=null;
rq.setCharacterEncoding("UTF-8");
// String gps = rq.getParameter("gps");
LOAD test = new LOAD();
test.SelectTable();
HttpSession session = rq.getSession();
//session.invalidate();
// session.removeAttribute("reportx");
session.setMaxInactiveInterval(3600);
session.setAttribute("reportx",JBx);
session.setAttribute("reporty",JBy);
rp.sendRedirect(rp.encodeRedirectURL("LOADPOST"));
}
public void doPost(HttpServletRequest rq, HttpServletResponse rp)
throws ServletException, IOException{
doGet(rq, rp);
}
}
Error message:
HTTP ERROR 500
Problem accessing /LOAD. Reason:
INTERNAL_SERVER_ERROR
Caused by:
java.lang.NullPointerException
at a.b.c.LOAD.SelectTable(LOAD.java:52)
at a.b.c.LOAD.doGet(LOAD.java:149)
at a.b.c.LOAD.doPost(LOAD.java:160)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:409)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Powered by Jetty://
To answer your question, yes it will cause definite failure.
There is no MySql instance to connect to on AppEngine. You need instead to use Google Cloud SQL.
It goes something like this:
DriverManager.registerDriver(new AppEngineDriver());
con = DriverManager.getConnection("jdbc:google:rdbms://instance_name/guestbook");
See: this AppEngine guide for the complete set of steps.
Note: To use the development server with a local MySQL instance, see https://developers.google.com/appengine/docs/java/cloud-sql/developers-guide#using_the_java_development_server