I am getting some error that I do not understand every time I try to run this program. The error seems to be triggered only when I have set these following lines BaseColorColumn.setCellValueFactory(new PropertyValueFactory<BaseColor, String>("BaseColor"));
and PriceColumn.setCellValueFactory(new PropertyValueFactory<BaseColor, Integer>("Price"));
I believe they're returning NULL but I am not sure why. I am basically just trying to fill in the table called CustomerTableView with data from BaseColor
//FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="supremeinkcalcmk2.MainController">
<left>
<VBox prefHeight="400.0" prefWidth="152.0" BorderPane.alignment="CENTER">
<children>
<TableView prefHeight="404.0" prefWidth="152.0">
<columns>
<TableColumn editable="false" prefWidth="75.0" sortable="false" text="Formla" />
<TableColumn editable="false" prefWidth="75.0" sortable="false" text="Price" />
</columns>
</TableView>
</children>
</VBox>
</left>
<right>
<VBox prefHeight="400.0" prefWidth="152.0" BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="ComboBoxSelectCustomer" prefWidth="150.0" promptText="Select Customer" />
<TableView fx:id="CustomerTableView" prefHeight="266.0" prefWidth="152.0">
<columns>
<TableColumn fx:id="BaseColor" prefWidth="75.0" text="Base Color" />
<TableColumn fx:id="Price" editable="false" prefWidth="75.0" sortable="false" text="Price" />
</columns>
</TableView>
<Button fx:id="ButtonSaveCustomer" mnemonicParsing="false" prefHeight="25.0" prefWidth="152.0" text="Save Customer" />
</children>
</VBox>
</right>
<center>
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Label layoutX="103.0" layoutY="122.0" text="Pantone Number" />
<TextField layoutX="74.0" layoutY="139.0" />
<Label fx:id="PriceLabel" layoutX="132.0" layoutY="293.0" />
<Button fx:id="ButtonCalculate" layoutX="113.0" layoutY="200.0" mnemonicParsing="false" onAction="#CalculateButton" text="Calculate" />
<Label layoutX="131.0" layoutY="285.0" text="Label" />
</children>
</Pane>
</center>
</BorderPane>
//MainController.Java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package supremeinkcalcmk2;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
/**
* FXML Controller class
*
* #author Archa
*/
public class MainController implements Initializable {
#FXML public ComboBox ComboBoxSelectCustomer;
#FXML private TableView<BaseColor> CustomerTableView;
#FXML private TableColumn<BaseColor, String> BaseColorColumn;
#FXML private TableColumn<BaseColor, Integer> PriceColumn;
//Customer TableView
ObservableList<BaseColor> data = FXCollections.observableArrayList(
new BaseColor("Yellow", 0),
new BaseColor("Green", 0),
new BaseColor("Blue", 0)
);
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
//CustomerTableView
BaseColorColumn.setCellValueFactory(new PropertyValueFactory<BaseColor, String>("BaseColor"));
PriceColumn.setCellValueFactory(new PropertyValueFactory<BaseColor, Integer>("Price"));
CustomerTableView.setItems(data);
}
public void CalculateButton(){
System.out.print("it is working!");
}
}
//BaseColor.Java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package supremeinkcalcmk2;
/**
*
* #author Arch
*/
public class BaseColor {
private String BaseColor;
private double Price;
public BaseColor(String BaseColor, double Price){
this.BaseColor = "";
this.Price = 0;
}
public String getBaseColor() {
return BaseColor;
}
public void setBaseColor(String BaseColor) {
this.BaseColor = BaseColor;
}
public double getPrice() {
return Price;
}
public void setPrice(double Price) {
this.Price = Price;
}
}
//Error log
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/1343441044.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
file:/D:/Programming/SupremeInkCalcMk2/dist/run103801275/SupremeInkCalcMk2.jar!/supremeinkcalcmk2/Main.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2583)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at supremeinkcalcmk2.SupremeInkCalcMk2.start(SupremeInkCalcMk2.java:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$53/726585699.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/355629945.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1149823713.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1915503092.run(Unknown Source)
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$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)
... 1 more
Caused by: java.lang.NullPointerException
at supremeinkcalcmk2.MainController.initialize(MainController.java:52)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 22 more
Exception running application supremeinkcalcmk2.SupremeInkCalcMk2
Java Result: 1
Your fx:ids do not match the field names:
<TableColumn fx:id="BaseColor" prefWidth="75.0" text="Base Color" />
<TableColumn fx:id="Price" editable="false" prefWidth="75.0" sortable="false" text="Price" />
but
#FXML private TableColumn<BaseColor, String> BaseColorColumn;
#FXML private TableColumn<BaseColor, Integer> PriceColumn;
Related
Why this exception is happening ,I tried to fix it but seeing no solution
but, I find no clue to solve those exceptions
//main
package filebrowser;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class FileBrowser extends Application
{
#Override
public void start(Stage stage) throws Exception{
Parent root=FXMLLoader.load(getClass().getResource("fileExplorer.fxml"));
Scene scene=new Scene(root);
stage.setTitle("Windows File Explorer");
stage.getIcons().add(new
Image(ClassLoader.getSystemResourceAsStream("filebrowser/application-x-executable.png")));
stage.setScene(scene);
stage.show();
}
public static void main(String[] args){
launch(args);
}
}
/*controller class this is the main control class i think error should be there but could not figure out it yet.
package filebrowser;
import java.io.File;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class FXMLcontroller{
#FXML
private ListView<String> listviewFiles;
#FXML
private TreeView<String> treeviewFileBrowse;
public void initialize() {
assert treeviewFileBrowse != null : "fx:id=\"treeviewFileBrowse\" was not injected: check your FXML file 'FileExplorer.fxml'.";
TreeItem<String> rootNode=new TreeItem<>("This PC",new ImageView(new Image(ClassLoader.getSystemResourceAsStream("filebrowser/computer.png"))));
Iterable<Path> rootDirectories=FileSystems.getDefault().getRootDirectories();
for(Path name:rootDirectories){
FilePathTreeItem treeNode=new FilePathTreeItem(new File(name.toString()));
rootNode.getChildren().add(treeNode);
}
rootNode.setExpanded(true);
this.treeviewFileBrowse.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.treeviewFileBrowse.setRoot(rootNode);
//this.listviewFiles.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}
}
//file path tree class
package filebrowser;
import java.io.File;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.TreeItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class FilePathTreeItem extends TreeItem<String>{
public static Image folderCollapseImage=new Image(ClassLoader.getSystemResourceAsStream("filebrowser/folder.png"));
public static Image folderExpandImage=new Image(ClassLoader.getSystemResourceAsStream("filebrowser/folder-open.png"));
public static Image fileImage=new Image(ClassLoader.getSystemResourceAsStream("filebrowser/text-x-generic.png"));
private boolean isLeaf;
private boolean isFirstTimeChildren=true;
private boolean isFirstTimeLeaf=true;
private final File file;
public File getFile(){return(this.file);}
private final String absolutePath;
public String getAbsolutePath(){return(this.absolutePath);}
private final boolean isDirectory;
public boolean isDirectory(){return(this.isDirectory);}
public FilePathTreeItem(File file){
super(file.toString());
this.file=file;
this.absolutePath=file.getAbsolutePath();
this.isDirectory=file.isDirectory();
if(this.isDirectory){
this.setGraphic(new ImageView(folderCollapseImage));
//add event handlers
this.addEventHandler(TreeItem.branchCollapsedEvent(),new EventHandler(){
#Override
public void handle(Event e){
FilePathTreeItem source=(FilePathTreeItem)e.getSource();
if(!source.isExpanded()){
ImageView iv=(ImageView)source.getGraphic();
iv.setImage(folderCollapseImage);
}
}
} );
this.addEventHandler(TreeItem.branchExpandedEvent(),new EventHandler(){
#Override
public void handle(Event e){
FilePathTreeItem source=(FilePathTreeItem)e.getSource();
if(source.isExpanded()){
ImageView iv=(ImageView)source.getGraphic();
iv.setImage(folderExpandImage);
}
}
} );
}
else{
this.setGraphic(new ImageView(fileImage));
}
//set the value (which is what is displayed in the tree)
String fullPath=file.getAbsolutePath();
if(!fullPath.endsWith(File.separator)){
String value=file.toString();
int indexOf=value.lastIndexOf(File.separator);
if(indexOf>0){
this.setValue(value.substring(indexOf+1));
}else{
this.setValue(value);
}
}
}
#Override
public ObservableList<TreeItem<String>> getChildren(){
if(isFirstTimeChildren){
isFirstTimeChildren=false;
super.getChildren().setAll(buildChildren(this));
}
return(super.getChildren());
}
#Override
public boolean isLeaf(){
if(isFirstTimeLeaf){
isFirstTimeLeaf=false;
isLeaf=this.file.isFile();
}
return(isLeaf);
}
private ObservableList<FilePathTreeItem> buildChildren(FilePathTreeItem treeItem){
File f=treeItem.getFile();
if((f!=null)&&(f.isDirectory())){
File[] files=f.listFiles();
if (files!=null){
ObservableList<FilePathTreeItem> children=FXCollections.observableArrayList();
for(File childFile:files){
children.add(new FilePathTreeItem(childFile));
}
return(children);
}
}
return FXCollections.emptyObservableList();
}
}
//FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.*?><?import javafx.scene.effect.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="filebrowser.FXMLcontroller">
<children>
<TreeView fx:id="treeviewFileBrowse" layoutX="2.0" layoutY="78.0"
prefHeight="304.0" prefWidth="171.0" />
<Button layoutX="14.0" layoutY="35.0" mnemonicParsing="false"
prefHeight="22.0" prefWidth="29.0" text="<" />
<MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="600.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Home">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Share">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="View">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
</menus>
</MenuBar>
<Button layoutX="43.0" layoutY="35.0" mnemonicParsing="false"
prefHeight="22.0" prefWidth="29.0" text=">" />
<TextField layoutX="475.0" layoutY="35.0" prefHeight="25.0"
prefWidth="111.0" promptText="Search quick text" />
<TableView layoutX="179.0" layoutY="78.0" prefHeight="304.0"
prefWidth="417.0">
<columns>
<TableColumn prefWidth="50.0" text="Icon" />
<TableColumn prefWidth="144.0" text="Name" />
<TableColumn minWidth="0.0" prefWidth="106.0" text="Date Modified" />
<TableColumn minWidth="0.0" prefWidth="69.0" text="Size" />
<TableColumn minWidth="0.0" prefWidth="45.0" text="Type" />
</columns>
</TableView>
<TextField layoutX="102.0" layoutY="35.0" prefHeight="25.0"
prefWidth="365.0" promptText="Search Here" />
<AmbientLight color="CHARTREUSE" lightOn="true" />
<PointLight color="CHARTREUSE" lightOn="true" />
</children>
</AnchorPane>`
//output exception
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
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 filebrowser.FileBrowser.start(FileBrowser.java:14)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more
Exception running application filebrowser.FileBrowser
Java Result: 1
I tried creating my own custom node, but I miserably failed somehow.
It always throws me an error when I try to run the controller/scene.
This is my class representing the custom node
package com.lollookup.scene.customcontrol;
import com.lollookup.scene.data.ChampionInfoData;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javax.xml.soap.Text;
import java.io.IOException;
/**
* #author Yasin
*/
public class ChampionInfo extends Pane {
#FXML
private ImageView championImage;
#FXML
private Text KDA;
#FXML
private Text winRate;
#FXML
private Text masteryScore;
#FXML
private Text masteryLevel;
public ChampionInfo() {
try {
Parent root = FXMLLoader.load(getClass().getResource("championinfo.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void setData(ChampionInfoData championInfoData) {
this.championImage.setImage(new Image(championInfoData.getUrl()));
this.KDA.setTextContent(championInfoData.getKDA());
this.winRate.setTextContent(championInfoData.getWinRate());
this.masteryScore.setTextContent(championInfoData.getMasteryScore());
this.masteryLevel.setTextContent(championInfoData.getMasteryLevel());
}
}
And this is my fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="84.0" prefWidth="238.0" type="Pane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.lollookup.scene.customcontrol.ChampionInfo">
<children>
<Separator layoutY="3.0" prefHeight="0.0" prefWidth="238.0" />
<HBox prefHeight="84.0" prefWidth="200.0">
<children>
<ImageView fx:id="championImage" fitHeight="72.0" fitWidth="66.0" pickOnBounds="true" preserveRatio="true">
<HBox.margin>
<Insets left="10.0" top="10.0" />
</HBox.margin>
</ImageView>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Text fx:id="KDA" strokeType="OUTSIDE" strokeWidth="0.0" text="kda">
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</Text>
<Text fx:id="winRate" strokeType="OUTSIDE" strokeWidth="0.0" text="winRate" />
<Text fx:id="masteryLevel" strokeType="OUTSIDE" strokeWidth="0.0" text="champLevel" />
<Text fx:id="masteryScore" strokeType="OUTSIDE" strokeWidth="0.0" text="champScore" />
</children>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</VBox>
</children>
</HBox>
<Separator layoutY="79.0" prefHeight="0.0" prefWidth="238.0" />
</children>
</fx:root>
My problem now is that somehow I can't really start/implement the custom node.
So no matter if I create a Scene like this:
package com.lollookup.scene.customcontrol;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* #author Yasin
*/
public class ChampionInfoExample extends Application {
#Override
public void start(Stage stage) throws Exception {
//ChampionInfo championInfo = new ChampionInfo(new ChampionInfoData("https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150", "1:1", "50%", "0", "1"));
ChampionInfo championInfo = new ChampionInfo();
//championInfo.setData(new ChampionInfoData("https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150", "1:1", "50%", "0", "1"));
stage.setScene(new Scene(championInfo));
stage.setTitle("Custom Control");
stage.setWidth(300);
stage.setHeight(200);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
or instantiate it like that:
Stream.of(championData).forEach(p -> championDataContainer.getChildren().add(new ChampionInfo()));
This is what is being thrown:
Exception in Application start method
Exception in thread "main" 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$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.StackOverflowError
at java.net.URLStreamHandler.setURL(URLStreamHandler.java:537)
at java.net.URLStreamHandler.parseURL(URLStreamHandler.java:304)
at sun.net.www.protocol.file.Handler.parseURL(Handler.java:67)
at java.net.URL.<init>(URL.java:615)
at java.net.URL.<init>(URL.java:483)
at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:1222)
at sun.misc.URLClassPath$FileLoader.findResource(URLClassPath.java:1212)
at sun.misc.URLClassPath$1.next(URLClassPath.java:240)
at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:354)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
at javax.xml.stream.FactoryFinder$1.run(FactoryFinder.java:352)
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:341)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:313)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:227)
at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:154)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2472)
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 com.lollookup.scene.customcontrol.ChampionInfo.<init>(ChampionInfo.java:38)
at sun.reflect.GeneratedConstructorAccessor2.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
What should I do?
I'd appreciate any kind of assistance
Thanks
Edit:
After debugging, I kinda found out why it was null. Had nothing to do with the codes given. Thank you StackOverflow!
Okay, I've been working through some issues with this program and I think I've finally gotten it to a point where I understand what is wrong. I'm trying to follow this tutorial a bit: http://docs.oracle.com/javafx/2/fxml_get_started/fxml_tutorial_intermediate.htm But my program has the add a row on a different FXML page than the Table View is on. I think the program is having trouble connecting the two. I've looked in to trying to find ways to make them talk to each other (put everything in one Controller and it didn't like it, tried passing the controller through the class and that didn't work {might have done it wrong though}). My program also has Integers and Doubles in it which are not covered in that tutorial so I've tried to figure those out on my own (probably better ways of doing it than I did).
But right now I'm just focused on figuring out why it keeps thinking
data = partTable.getItems();
Is null (line 77 in AddPartController). Any help or other FXML/JavaFX tutorials would be greatly appreciated (though I've already looked through a lot of them).
FXMLDocument.fxml (main page)
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.collections.*?>
<?import fxmltableview.*?>
<?import ims.Part?>
<?import ims.Inhouse?>
<?import ims.Outsourced?>
<BorderPane id="main" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ims.FXMLDocumentController" >
<top>
<Label fx:id="mainTitle" text="Inventory Management System" />
</top>
<center>
<HBox fx:id="holding">
<children>
<VBox styleClass="contentBox">
<children>
<HBox styleClass="topBox">
<HBox styleClass="subHeading">
<Label text="Parts" />
</HBox>
<HBox styleClass="searchBox">
<Button text="Search" />
<TextField />
</HBox>
</HBox>
<TableView fx:id="partTable" styleClass="dataTable">
<columns>
<TableColumn text="Part ID">
<cellValueFactory>
<PropertyValueFactory property="id" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="nameColumn" text="Part Name">
<cellValueFactory>
<PropertyValueFactory property="name" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Inventory Level">
<cellValueFactory>
<PropertyValueFactory property="instock" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Price/Cost per Unit">
<cellValueFactory>
<PropertyValueFactory property="price" />
</cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<Inhouse name="Part 1" price="5.00" instock="5" max="10" min="1" />
<Inhouse name="Part 2" price="7.00" instock="2" max="11" min="2" />
</FXCollections>
</items>
<sortOrder>
<fx:reference source="nameColumn" />
</sortOrder>
</TableView>
<HBox styleClass="modificationButtons">
<children>
<Button onAction="#addPart" text="Add" />
<Button onAction="#modifyPart" text="Modify" />
<Button text="Delete" />
</children>
</HBox>
</children>
</VBox>
<VBox styleClass="contentBox">
<children>
<HBox styleClass="topBox">
<HBox styleClass="subHeading">
<Label text="Products" />
</HBox>
<HBox styleClass="searchBox">
<Button text="Search" />
<TextField />
</HBox>
</HBox>
<TableView fx:id="productTable" styleClass="dataTable">
<columns>
<TableColumn text="Part ID" />
<TableColumn text="Part Name" />
<TableColumn text="Inventory Level" />
<TableColumn text="Price/Cost per Unit" />
</columns>
</TableView>
<HBox styleClass="modificationButtons">
<children>
<Button onAction="#addProduct" text="Add" />
<Button onAction="#modifyProduct" text="Modify" />
<Button text="Delete" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</center>
<bottom>
<HBox fx:id="exitButton">
<children>
<Button onAction="#closeProgram" text="Exit" />
</children>
</HBox>
</bottom>
</BorderPane>
FXMLDocumentController
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ims;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
/**
*
* #author chelseacamper
*/
public class FXMLDocumentController implements Initializable {
#FXML
private Label label;
#FXML
private void addPart(ActionEvent event) throws IOException {
Parent add_part_parent = FXMLLoader.load(getClass().getResource("addPart.fxml"));
Scene add_part_scene = new Scene(add_part_parent);
add_part_scene.getStylesheets().add("style.css");
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(add_part_scene);
app_stage.show();
}
#FXML
private void modifyPart(ActionEvent event) throws IOException {
Parent modify_part_parent = FXMLLoader.load(getClass().getResource("modifyPart.fxml"));
Scene modify_part_scene = new Scene(modify_part_parent);
modify_part_scene.getStylesheets().add("style.css");
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(modify_part_scene);
app_stage.show();
}
#FXML
private void addProduct(ActionEvent event) throws IOException {
Parent add_product_parent = FXMLLoader.load(getClass().getResource("addProduct.fxml"));
Scene add_product_scene = new Scene(add_product_parent);
add_product_scene.getStylesheets().add("style.css");
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(add_product_scene);
app_stage.show();
}
#FXML
private void modifyProduct(ActionEvent event) throws IOException {
Parent modify_product_parent = FXMLLoader.load(getClass().getResource("modifyProduct.fxml"));
Scene modify_product_scene = new Scene(modify_product_parent);
modify_product_scene.getStylesheets().add("style.css");
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(modify_product_scene);
app_stage.show();
}
#FXML
private void closeProgram(ActionEvent event) throws IOException {
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.close();
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
addPart.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane id="addPage" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ims.AddPartController">
<fx:define>
<ToggleGroup fx:id="inOutGroup" />
</fx:define>
<center>
<VBox fx:id="verticalHolding">
<children>
<HBox fx:id="topRow">
<Label text="Add Part"/>
<RadioButton fx:id="inhouse" toggleGroup="$inOutGroup" text="In-House"/>
<RadioButton fx:id="outsourced" toggleGroup="$inOutGroup" selected="true" text="Outsourced"/>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
<Label text="ID" />
</HBox>
<HBox styleClass="halfWidthRight">
<TextField promptText="Auto Gen - Disabled" />
</HBox>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
<Label text="Name" />
</HBox>
<HBox styleClass="halfWidthRight">
<TextField fx:id="partNameField" promptText="Part Name" />
</HBox>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
<Label text="Inv" />
</HBox>
<HBox styleClass="halfWidthRight">
<TextField fx:id="partInstockField" promptText="Inv" />
</HBox>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
<Label text="Price/Cost" />
</HBox>
<HBox styleClass="halfWidthRight">
<TextField fx:id="partPriceField" promptText="Price/Cost" />
</HBox>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
<Label text="Max" />
</HBox>
<HBox styleClass="halfWidthRight">
<TextField styleClass="smallTextField" fx:id="partMaxField" promptText="Max" />
<Label text="Min" />
<TextField styleClass="smallTextField" fx:id="partMinField" promptText="Min" />
</HBox>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
<Label fx:id="inhouseLabel" text="Machine ID" />
<Label fx:id="outsourcedLabel" text="Company Name" />
</HBox>
<HBox styleClass="halfWidthRight">
<TextField fx:id="inhouseTextField" promptText="Mach ID" />
<TextField fx:id="outsourcedTextField" promptText="Comp Nm" />
</HBox>
</HBox>
<HBox styleClass="fullWidth">
<HBox styleClass="halfWidthLeft">
</HBox>
<HBox styleClass="halfWidthRight">
<Button onAction="#addInhouse" text="Save" />
<Button onAction="#backToMain" text="Cancel" />
</HBox>
</HBox>
</children>
</VBox>
</center>
</BorderPane>
AddPartController
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ims;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* #author chelseacamper
*/
public class AddPartController implements Initializable {
#FXML
ToggleButton inhouse;
#FXML
ToggleButton outsourced;
#FXML
Label inhouseLabel;
#FXML
Label outsourcedLabel;
#FXML
TextField inhouseTextField;
#FXML
TextField outsourcedTextField;
#FXML
private TableView<Inhouse> partTable;
#FXML
private TextField partNameField;
#FXML
private TextField partInstockField;
#FXML
private TextField partPriceField;
#FXML
private TextField partMaxField;
#FXML
private TextField partMinField;
/**
* Initializes the controller class.
* #param url
* #param rb
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
inhouseLabel.visibleProperty().bind( inhouse.selectedProperty() );
outsourcedLabel.visibleProperty().bind( outsourced.selectedProperty() );
inhouseTextField.visibleProperty().bind( inhouse.selectedProperty() );
outsourcedTextField.visibleProperty().bind( outsourced.selectedProperty() );
inhouseLabel.managedProperty().bind( inhouse.selectedProperty() );
outsourcedLabel.managedProperty().bind( outsourced.selectedProperty() );
inhouseTextField.managedProperty().bind( inhouse.selectedProperty() );
outsourcedTextField.managedProperty().bind( outsourced.selectedProperty() );
}
#FXML
public void addInhouse(ActionEvent event){
ObservableList<Inhouse> data;
data = partTable.getItems();
data.add(new Inhouse(partNameField.getText(),
Integer.parseInt(partInstockField.getText()),
Double.parseDouble(partPriceField.getText()),
Integer.parseInt(partMaxField.getText()),
Integer.parseInt(partMinField.getText()),
Integer.parseInt(inhouseTextField.getText())
// Integer.parseInt(outsourcedTextField.getText())
));
partNameField.setText("");
partInstockField.setText(String.valueOf(partInstockField));
partPriceField.setText(String.valueOf(partPriceField));
partMaxField.setText(String.valueOf(partMaxField));
partMinField.setText(String.valueOf(partMinField));
inhouseTextField.setText(String.valueOf(inhouseTextField));
// outsourcedTextField.setText(String.valueOf(outsourcedTextField));
}
#FXML
private void backToMain(ActionEvent event) throws IOException {
Parent add_main_parent = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene add_main_scene = new Scene(add_main_parent);
add_main_scene.getStylesheets().add("style.css");
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(add_main_scene);
app_stage.show();
}
}
Errors that you get when you click add and then Save (don't even have to enter stuff)
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1770)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653)
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:8390)
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:3758)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
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$350(GlassViewEventHandler.java:385)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$294/109927940.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:927)
Caused by: 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:497)
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:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1765)
... 46 more
Caused by: java.lang.NullPointerException
at ims.AddPartController.addInhouse(AddPartController.java:77)
... 56 more
The is no element in addPart.fxml with fx:id="partTable". Consequently partTable is null, and
partTable.getItems();
throws a null pointer exception.
You need to inject partTable into the controller for the FXML in which it is defined:
public class FXMLDocumentController implements Initializable {
#FXML
private Label label;
#FXML
private TableView<Inhouse> partTable ;
// ...
}
The AddPartController only needs access to the list of items associated with the table, so you can define a field for it, and a method for initializing it:
public class AddPartController implements Initializable {
// ...
private ObservableList<Inhouse> tableItems ;
public void setTableItems(ObservableList<Inhouse> tableItems) {
this.tableItems = tableItems ;
}
// ...
}
Then set the items when you load addPart.fxml:
#FXML
private void addPart(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("addPart.fxml"));
Parent add_part_parent = loader.load();
AddPartController addPartController = loader.getController();
addPartController.setTableItems(partTable.getItems());
Scene add_part_scene = new Scene(add_part_parent);
add_part_scene.getStylesheets().add("style.css");
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(add_part_scene);
app_stage.show();
}
and then of course you just need
#FXML
public void addInhouse(ActionEvent event){
tableItems.add(new Inhouse(partNameField.getText(),
Integer.parseInt(partInstockField.getText()),
Double.parseDouble(partPriceField.getText()),
Integer.parseInt(partMaxField.getText()),
Integer.parseInt(partMinField.getText()),
Integer.parseInt(inhouseTextField.getText())
// Integer.parseInt(outsourcedTextField.getText())
));
}
(FWIW I have no idea what
partInstockField.setText(String.valueOf(partInstockField));
etc etc is supposed to do.)
I've created a simple ComboBox which I am trying to populate with data from an sqlite file. The error I am getting is stating that it cannot find the file or it cannot find the table so I am unsure whats going on. The sql file is located in my project folder so I don't think thats the issue and my table looks fine so not sure if its that either.
//Error log
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: CustomerPriceList)
Error Building ComboBox Data
at org.sqlite.core.DB.newSQLException(DB.java:890)
at org.sqlite.core.DB.newSQLException(DB.java:901)
at org.sqlite.core.DB.throwex(DB.java:868)
at org.sqlite.core.NativeDB.prepare(Native Method)
at org.sqlite.core.DB.prepare(DB.java:211)
at org.sqlite.jdbc3.JDBC3Statement.executeQuery(JDBC3Statement.java:81)
at supremeinkcalcmk2.MainController.buildData(MainController.java:87)
at supremeinkcalcmk2.MainController.initialize(MainController.java:55)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at supremeinkcalcmk2.SupremeInkCalcMk2.start(SupremeInkCalcMk2.java:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$53/726585699.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/355629945.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1149823713.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1915503092.run(Unknown Source)
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$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
//SqlConnection
package supremeinkcalcmk2;
import java.sql.Connection;
import java.sql.DriverManager;
public class SqlConnection {
public static Connection CustomerConnection() {
try {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:CustomerSQLDB.sqlite");
return conn;
} catch (Exception e) {
return null;
}
}
}
//MainController
package supremeinkcalcmk2;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javax.swing.DefaultComboBoxModel;
public class MainController implements Initializable {
#FXML
public ComboBox<String> ComboBoxSelectCustomer;
Connection connection;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
buildData();
}
//combobox sql connection
public void buildData() {
ObservableList<String> data = FXCollections.observableArrayList();
connection = SqlConnection.CustomerConnection();
try {
String SQL = "Select Name From CustomerPriceList";
ResultSet rs = connection.createStatement().executeQuery(SQL);
while(rs.next()){
data.add(rs.getString("Name"));
}
ComboBoxSelectCustomer.setItems(data);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error Building ComboBox Data");
}
if (connection == null) {
System.exit(1);
System.out.println("Connection failed");
}
}
public boolean isDbConnected() {
try {
return connection.isClosed();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
}
//Main.FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="supremeinkcalcmk2.MainController">
<left>
<VBox prefHeight="400.0" prefWidth="152.0" BorderPane.alignment="CENTER">
<children>
<TableView prefHeight="578.0" prefWidth="152.0">
<columns>
<TableColumn editable="false" prefWidth="75.0" sortable="false" text="Formla" />
<TableColumn editable="false" prefWidth="75.0" sortable="false" text="Price" />
</columns>
</TableView>
<Button fx:id="ButtonNewPantone" mnemonicParsing="false" prefHeight="25.0" prefWidth="155.0" text="Add New Pantone" />
</children>
</VBox>
</left>
<right>
<VBox prefHeight="400.0" prefWidth="152.0" BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="ComboBoxSelectCustomer" prefWidth="150.0" promptText="Select Customer" />
<TableView fx:id="CustomerTableView" prefHeight="557.0" prefWidth="152.0">
<columns>
<TableColumn fx:id="BaseColor" prefWidth="75.0" sortable="false" text="Base Color" />
<TableColumn fx:id="Price" editable="true" prefWidth="75.0" sortable="false" text="Price" />
</columns>
</TableView>
<Button fx:id="ButtonSaveCustomer" mnemonicParsing="false" prefHeight="25.0" prefWidth="152.0" text="Save Customer" />
</children>
</VBox>
</right>
<center>
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Label layoutX="203.0" layoutY="193.0" text="Pantone Number" />
<TextField layoutX="173.0" layoutY="220.0" />
<Label fx:id="PriceLabel" layoutX="132.0" layoutY="293.0" />
<Button fx:id="ButtonCalculate" layoutX="216.0" layoutY="290.0" mnemonicParsing="false" onAction="#CalculateButton" text="Calculate" />
<Label layoutX="234.0" layoutY="446.0" text="Label" />
</children>
</Pane>
</center>
</BorderPane>
//Database
CREATE TABLE `CustomerPriceList` (
`Name` TEXT NOT NULL UNIQUE,
`Test` INTEGER,
PRIMARY KEY(Name)
)
Issue was that the sql file's extension was .db and not .sqilite
Correct format inside the Sqlconnection.java file:
Connection conn = DriverManager.getConnection("jdbc:sqlite:CustomerSQLDB.db");
i have a problem with javaFX.I'm doing calculator and i divide my app between 3 FXML files(1 is a controller which controlls only numbers and operators, 2 is a controller for textfield which is result field, and last one should let them communicate which each other).
I can not manage how can i write my own method which for example put number "3" when i press number 3 in textfield-which is in other FXML and has its own fxml file.There is a nullpointer exception so i suppose im not initializing this textfield.Please help me with this problem.Is there any way to write my own method(in this example i wrote showDigit()) in MainController class - this method should set Text to textfield after pressing button - for example button 2 will put "2" in textfield.
Below I've pasted my code.
package pl.calculator.controller;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
public class MainPaneController implements Initializable {
#FXML
private TextPaneController textPaneController;
#FXML
private CalculatorPaneController calculatorPaneController;
#Override
public void initialize(URL location, ResourceBundle resources) {
/*calculatorPaneController.getButtonZero().setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
textPaneController.getTextFieldExpression().setText("example");
}
});*/ --- < THIS WORKS
}
}
FXML for MainController
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="pl.calculator.controller.MainPaneController">
<children>
<fx:include fx:id="textPane" source="TextPane.fxml" />
<fx:include fx:id="calculatorPane" source="CalculatorPane.fxml" />
</children>
</VBox>
Number and operation controller:
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
public class CalculatorPaneController implements Initializable {
#FXML
private Button buttonFour;
#FXML
private Button buttonSix;
#FXML
private Button buttonDivide;
#FXML
private Button buttonOne;
#FXML
private Button buttonCloseBracket;
#FXML
private Button buttonDot;
#FXML
private Button buttonClear;
#FXML
private Button buttonTwo;
#FXML
private Button buttonSeven;
#FXML
private Button buttonOpenBracket;
#FXML
private Button buttonThree;
#FXML
private Button buttonMultiply;
#FXML
private Button buttonSubtract;
#FXML
private Button buttonEight;
#FXML
private Button buttonEqual;
#FXML
private Button buttonNine;
#FXML
private Button buttonZero;
#FXML
private Button buttonMemory;
#FXML
private Button buttonFive;
#FXML
private GridPane gridPane;
#FXML
private Button buttonAdd;
#FXML
private TextPaneController textPaneController;
#FXML
private CalculatorPaneController calculatorPaneController;
#Override
public void initialize(URL location, ResourceBundle resources) {
}
#FXML
private void showDigit(ActionEvent event) {
textPaneController.getTextFieldExpression().setText("s");
} <---------THIS ONE DOESNT WORK
public Button getButtonFour() {
return buttonFour;
}
public void setButtonFour(Button buttonFour) {
this.buttonFour = buttonFour;
}
public Button getButtonSix() {
return buttonSix;
}
public void setButtonSix(Button buttonSix) {
this.buttonSix = buttonSix;
}
public Button getButtonDivide() {
return buttonDivide;
}
public void setButtonDivide(Button buttonDivide) {
this.buttonDivide = buttonDivide;
}
public Button getButtonOne() {
return buttonOne;
}
public void setButtonOne(Button buttonOne) {
this.buttonOne = buttonOne;
}
public Button getButtonCloseBracket() {
return buttonCloseBracket;
}
public void setButtonCloseBracket(Button buttonCloseBracket) {
this.buttonCloseBracket = buttonCloseBracket;
}
public Button getButtonDot() {
return buttonDot;
}
public void setButtonDot(Button buttonDot) {
this.buttonDot = buttonDot;
}
public Button getButtonClear() {
return buttonClear;
}
public void setButtonClear(Button buttonClear) {
this.buttonClear = buttonClear;
}
public Button getButtonTwo() {
return buttonTwo;
}
public void setButtonTwo(Button buttonTwo) {
this.buttonTwo = buttonTwo;
}
public Button getButtonSeven() {
return buttonSeven;
}
public void setButtonSeven(Button buttonSeven) {
this.buttonSeven = buttonSeven;
}
public Button getButtonOpenBracket() {
return buttonOpenBracket;
}
public void setButtonOpenBracket(Button buttonOpenBracket) {
this.buttonOpenBracket = buttonOpenBracket;
}
public Button getButtonThree() {
return buttonThree;
}
public void setButtonThree(Button buttonThree) {
this.buttonThree = buttonThree;
}
public Button getButtonMultiply() {
return buttonMultiply;
}
public void setButtonMultiply(Button buttonMultiply) {
this.buttonMultiply = buttonMultiply;
}
public Button getButtonSubtract() {
return buttonSubtract;
}
public void setButtonSubtract(Button buttonSubtract) {
this.buttonSubtract = buttonSubtract;
}
public Button getButtonEight() {
return buttonEight;
}
public void setButtonEight(Button buttonEight) {
this.buttonEight = buttonEight;
}
public Button getButtonEqual() {
return buttonEqual;
}
public void setButtonEqual(Button buttonEqual) {
this.buttonEqual = buttonEqual;
}
public Button getButtonNine() {
return buttonNine;
}
public void setButtonNine(Button buttonNine) {
this.buttonNine = buttonNine;
}
public Button getButtonZero() {
return buttonZero;
}
public void setButtonZero(Button buttonZero) {
this.buttonZero = buttonZero;
}
public Button getButtonMemory() {
return buttonMemory;
}
public void setButtonMemory(Button buttonMemory) {
this.buttonMemory = buttonMemory;
}
public Button getButtonFive() {
return buttonFive;
}
public void setButtonFive(Button buttonFive) {
this.buttonFive = buttonFive;
}
public GridPane getGridPane() {
return gridPane;
}
public void setGridPane(GridPane gridPane) {
this.gridPane = gridPane;
}
public Button getButtonAdd() {
return buttonAdd;
}
public void setButtonAdd(Button buttonAdd) {
this.buttonAdd = buttonAdd;
}
}
FXML for operation and number controller:
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane fx:id="gridPane" prefHeight="308.0" prefWidth="375.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pl.calculator.controller.CalculatorPaneController">
<children>
<Button fx:id="buttonOne" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" onAction="#showDigit" text="1" />
<Button fx:id="buttonFour" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="4" GridPane.rowIndex="1" />
<Button fx:id="buttonTwo" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="2" GridPane.columnIndex="1" />
<Button fx:id="buttonSeven" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="7" GridPane.rowIndex="2" />
<Button fx:id="buttonFive" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="5" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button fx:id="buttonEight" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="8" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Button fx:id="buttonThree" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="3" GridPane.columnIndex="2" />
<Button fx:id="buttonSix" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="6" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Button fx:id="buttonNine" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="9" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Button fx:id="buttonZero" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="0" GridPane.rowIndex="3" />
<Button fx:id="buttonDot" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="." GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Button fx:id="buttonEqual" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="=" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Button fx:id="buttonDivide" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="/" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Button fx:id="buttonMultiply" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="*" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<Button fx:id="buttonSubtract" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="-" GridPane.columnIndex="3" GridPane.rowIndex="1" />
<Button fx:id="buttonAdd" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="+" GridPane.columnIndex="3" />
<Button fx:id="buttonCloseBracket" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text=")" GridPane.columnIndex="4" GridPane.rowIndex="3" />
<Button fx:id="buttonOpenBracket" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="(" GridPane.columnIndex="4" GridPane.rowIndex="2" />
<Button fx:id="buttonMemory" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="M" GridPane.columnIndex="4" />
<Button fx:id="buttonClear" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" text="C" GridPane.columnIndex="4" GridPane.rowIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
Controller for textfields(results)
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class TextPaneController {
#FXML
private Label labelExpression;
#FXML
private TextField textFieldOnp;
#FXML
private Label labelOnp;
#FXML
private TextField textFieldExpression;
public Label getLabelExpression() {
return labelExpression;
}
public void setLableExpression(Label lableExpression) {
this.labelExpression = lableExpression;
}
public TextField getTextFieldOnp() {
return textFieldOnp;
}
public void setTextFieldOnp(TextField textFieldOnp) {
this.textFieldOnp = textFieldOnp;
}
public Label getLabelOnp() {
return labelOnp;
}
public void setLabelOnp(Label labelOnp) {
this.labelOnp = labelOnp;
}
public TextField getTextFieldExpression() {
return textFieldExpression;
}
public void setTextFieldExpression(TextField textFieldExpression) {
this.textFieldExpression = textFieldExpression;
}
}
FXML File for TExt:
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="89.0" prefWidth="349.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pl.calculator.controller.TextPaneController">
<children>
<Label fx:id="lableExpression" layoutX="21.0" layoutY="14.0" text="Wprowadź wyrażenie:" />
<Label fx:id="labelOnp" layoutX="213.0" layoutY="14.0" text="Wyrażenie ONP" />
<TextField fx:id="textFieldExpression" layoutX="5.0" layoutY="45.0" />
<TextField fx:id="textFieldOnp" editable="false" layoutX="180.0" layoutY="45.0" />
</children>
</AnchorPane>
and stack trace:
TextField[id=textFieldExpression, styleClass=text-input text-field]
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1800(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 48 more
Caused by: java.lang.NullPointerException
at pl.calculator.controller.CalculatorPaneController.showDigit(CalculatorPaneController.java:89)
... 57 more
The FXML file CalculatorPane.fxml doesn't have an <fx:include fx:id="textPane" ... />, so the associated controller doesn't get a textPaneController injected into it. Thus textPaneController in CalculatorPaneController is null, and you get the NullPointerException.
A way to update the value from the CalculatorPaneController is to give both controllers a shared data model, and update the model. So you could do something like
public class DataModel {
private final StringProperty text = new SimpleStringProperty();
public StringProperty textProperty() {
return text ;
}
public final String getText() {
return textProperty().get();
}
public final void setText(String text) {
textProperty().set(text);
}
// other properties as needed...
}
Then you controllers can do
public class TextPaneController {
private DataModel model ;
#FXML
private TextField textFieldExpression ;
// etc ...
public void setModel(DataModel model) {
this.model = model ;
textFieldExpression.textProperty().bindBidirectional(model.textProperty());
}
}
and
public class CalculatorPaneController {
private DataModel model ;
public void setModel(DataModel model) {
this.model = model ;
}
// ...
#FXML
private void showDigit(ActionEvent event) {
model.setText("s");
}
}
Finally, you tie everything together in the main controller's initialize method:
public class MainPaneController implements Initializable {
#FXML
private TextPaneController textPaneController;
#FXML
private CalculatorPaneController calculatorPaneController;
#Override
public void initialize(URL location, ResourceBundle resources) {
DataModel model = new DataModel();
textPaneController.setModel(model);
calculatorPaneController.setModel(model);
}
}
You really don't need (and shouldn't have) all the get/set methods for the controls in the controllers. Those should be kept private and not exposed outside the controller.