So I've been working on a JavaFX program (quick project for my college class because my college was going to allow me to sit for a certification exam as my course project, but with COVID-19 that went out the window with the college going fully online). The program complied (using the javac command) with no errors. However, when I attempt to run (using the java command) the program, I get a list of errors:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NumberFormatException: For input string: "[D@74015eb0"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at Main.start(Main.java:37)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$4(WinApplication.java:186)
... 1 more
Exception running application Main
Every other question I've seen asked with these errors involved at least one FXML file, a language I am not familiar with. My code is below (I structured it based off another version of the same program, but it was C++11 without any other language or external libraries for GUI; and I apologize for the shear size of the code). How would I resolve the issues? (In case anybody is wondering: This is my first time in a year since I last used Java, and this is my very first time using JavaFX.)
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javax.swing.JOptionPane;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.Scanner;
import java.util.Date;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
String busName = "";
String busAddress = "";
final int[] cCI = {1}; //Declared so it can be reassigned a number from within EventHandler.
cCI[0] = 1; //Will be changed later if assigned radio button is modified later.
final boolean[] sTax = {false};
boolean salesTaxAdd = sTax[0];
final int[] SalesTax = {1};
SalesTax[0] = 0; //Will be changed later if assigned radio button is modified later.
//Variables for storing sales tax info.
final String[] stpString = {"0.00"};
final double[] salesTaxPercent = {Double.parseDouble(stpString[0]) / 100};
setTaxPercent(Double.parseDouble(String.valueOf(salesTaxPercent)), 2);
final boolean[] radioCheck = {true}; //initializes value for UDF, UDF will change if R.B. is interacted with.
businessInfo(busName);
businessAddress(busAddress);
primaryStage.setTitle("Final Project - Business Program v2.0 - J.D.K. S.E. 8 Update 241");
//Defining Grid Pane
GridPane gridPane = new GridPane();
gridPane.setMinSize(3,3);
Scene scene = new Scene(gridPane);
primaryStage.setScene(scene);
//Event Handlers
EventHandler<ActionEvent> transaction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
operatingProcedures(1, busName, busAddress, cCI[0], salesTaxPercent[0], SalesTax[0]);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
};
EventHandler<ActionEvent> cost = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
operatingProcedures(2, busName, busAddress, cCI[0], salesTaxPercent[0], SalesTax[0]);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
};
EventHandler<ActionEvent> endOfDay = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
operatingProcedures(3, busName, busAddress, cCI[0], salesTaxPercent[0], SalesTax[0]);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
};
EventHandler<ActionEvent> resetName = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
businessInfo(busName);
businessAddress(busAddress);
} catch (IOException e) {
e.printStackTrace();
}
}
};
EventHandler<ActionEvent> radioChanged = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
if (radioCheck[0] == true) {
setRadio(false);
}
if (radioCheck[0] == false){
setRadio(true);
}
} catch (IOException e) {
e.printStackTrace();
}
cCI[0] = 2; //Tells system not to collect customer information.
}
};
EventHandler<ActionEvent> toAddSalesTax = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try{
if (sTax[0] == false) {
addTax(true);
SalesTax[0] = 1;
stpString[0] = JOptionPane.showInputDialog("Enter your state's sales tax as a decimal (or the percent divided by 100):");
setTaxPercent(Double.parseDouble(String.valueOf(salesTaxPercent)), 1);
}
if (sTax[0] == true){
addTax(false);
SalesTax[0] = 0;
}
}
catch (IOException e){
e.printStackTrace();
}
}
};
//Defining Buttons
Button revenue = new Button("Conduct Transaction");
revenue.setOnAction(transaction);
Button expense = new Button ("Record Expense");
expense.setOnAction(cost);
Button eod = new Button ("End of Day (Close)");
eod.setOnAction(endOfDay);
Button changeName = new Button("Change Business Name");
changeName.setOnAction(resetName);
//Setting for Collecting Customer's address & accompanying boolean to be stored
setRadio(radioCheck[0]);
RadioButton collectInfo = new RadioButton("Collect Customer's Address?");
collectInfo.setSelected(radioCheck[0]);
collectInfo.setOnAction(radioChanged);
//Setting for Sales Tax
addTax(salesTaxAdd);
RadioButton stateSalesTax = new RadioButton("Add State Sales Tax");
stateSalesTax.setSelected(sTax[0]);
//Business Name label
Text text = new Text(busName);
//Add widgets to GridPane
gridPane.add(text, 1, 0);
gridPane.add(revenue, 0, 1);
gridPane.add(expense, 1, 1);
gridPane.add(eod, 2, 1);
gridPane.add(changeName, 0, 2);
gridPane.add(collectInfo, 1, 2);
gridPane.add(stateSalesTax, 2, 2);
primaryStage.show();
}
//Start User-Defined Functions of the Program.
public static double setTaxPercent (double taxInfo, int saveLoad) throws IOException{
if (saveLoad == 1){
//Saving Function;
try{
PrintWriter saveInfo = new PrintWriter("taxPercent.dat");
saveInfo.print(taxInfo);
saveInfo.close();
}
catch (FileNotFoundException e){
File file = new File ("taxPercent.dat");
PrintWriter outputFile = new PrintWriter("taxPercent.dat");
outputFile.print(taxInfo);
outputFile.close();
}
}
if (saveLoad == 2){
//Loading Function;
try{
FileInputStream load = new FileInputStream("taxPercent.dat");
taxInfo = load.read();
load.close();
}
catch (FileNotFoundException e){
//Prepare File and preload default setting
File file = new File ("taxPercent.dat");
PrintWriter outputFile = new PrintWriter("taxPercent.dat");
outputFile.print(0.00);
outputFile.close();
}
}
return taxInfo;
}
public static boolean addTax (boolean tax) throws IOException{
try{
FileInputStream ast = new FileInputStream("addSalesTax.dat");
DataInputStream astBoolean = new DataInputStream(ast);
tax = astBoolean.readBoolean();
astBoolean.close();
ast.close();
}
catch (FileNotFoundException e){
File file = new File ("addSalesTax.dat");
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(tax);
dos.close();
fos.close();
}
return tax;
}
public static boolean setRadio (boolean radio) throws IOException{
//Loads and Saves state of Radio Button
try{
FileInputStream rc = new FileInputStream("radio.dat");
DataInputStream checkRadio = new DataInputStream(rc);
radio = checkRadio.readBoolean();
checkRadio.close();
rc.close();
}
catch (FileNotFoundException e){
File file = new File ("radio.dat");
FileOutputStream fos = new FileOutputStream("radio.dat");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(radio);
dos.close();
fos.close();
}
return radio;
}
public static String businessInfo (String varName) throws IOException {
//Name will be stored in a Data file vice a Text file
try {
FileInputStream in = null;
//Name
in = new FileInputStream("Name.dat");
Scanner read = new Scanner(in);
varName = read.nextLine();
read.close();
in.close();
}
catch (FileNotFoundException e) {
File file = new File("Name.dat");
varName = JOptionPane.showInputDialog("Enter your business's name:");
PrintWriter outputFile = new PrintWriter("Name.dat");
outputFile.print(varName);
outputFile.close();
}
return varName;
}
public static String businessAddress (String varAddress) throws IOException{
String varStreet, varCity, varST, varZIP;
try{
FileInputStream address = null;
//Street Address
address = new FileInputStream("Street.dat");
Scanner street = new Scanner(address);
varStreet = street.nextLine();
street.close();
address.close();
//City
address = new FileInputStream("City.dat");
Scanner city = new Scanner(address);
varCity = city.nextLine();
city.close();
address.close();
//State (ST)
address = new FileInputStream("State.dat");
Scanner state = new Scanner(address);
varST = state.nextLine();
state.close();
address.close();
//Zip w/out 4 code
address = new FileInputStream("zip.dat");
Scanner zip = new Scanner(address);
varZIP = zip.nextLine();
zip.close();
address.close();
}
catch (FileNotFoundException e){
//Street
File file = new File ("Street.dat");
varStreet = JOptionPane.showInputDialog("Enter your business's street address:");
PrintWriter outputFile = new PrintWriter("Street.dat");
outputFile.print(varStreet);
outputFile.close();
//City
file = new File ("City.dat");
varCity = JOptionPane.showInputDialog("Please enter the city (don't include the state) is your business in?");
outputFile = new PrintWriter("City.dat");
outputFile.print(varCity);
outputFile.close();
//State
file = new File ("State.dat");
varST = JOptionPane.showInputDialog("Please enter the state your business is located in.");
outputFile = new PrintWriter("State.dat");
outputFile.print(varST);
outputFile.close();
//ZIP
file = new File ("zip.dat");
varZIP = JOptionPane.showInputDialog("Please enter your ZIP address (4-code not needed).");
outputFile = new PrintWriter("zip.dat");
outputFile.print(varZIP);
outputFile.close();
}
varAddress = varStreet + "\n" + varCity + ", " + varST + " " + varZIP;
return varAddress;
}
public static void operatingProcedures(int opSelection, String theName, String theAddress, int ica, double theTax, int useTax) throws FileNotFoundException {
int x = 1; //Used for Revenue arrays
int y = 1; //Used for Expense arrays
String[] revenueName = new String [x];
double[] revenueValue = new double [x];
String[] expenseName = new String [y];
double[] expenseValue = new double [y];
double totalRevenue = 0; //Used in EOD Procedures
double totalExpense = 0; //Used in EOD Procedures
double netIncome; //Used in EOD Procedures; will state a net gain or net loss for the day.
if (opSelection == 1){
int numItems;
//Revenue Reporting
if (ica == 1){
//This procedure collects customer information
String customerName, customerStreet, customerCity, customerST;
int customerZIP;
customerName = JOptionPane.showInputDialog("Enter the customer's name:");
customerStreet = JOptionPane.showInputDialog("Enter the customer's street address; without city, state, or zip code:");
customerCity = JOptionPane.showInputDialog("Enter the customer's city:");
customerST = JOptionPane.showInputDialog("Enter the customer's abbreviated (i.e \"FL\" for \"Florida\": ");
customerZIP = Integer.parseInt(JOptionPane.showInputDialog("Enter the customer's ZIP code:"));
numItems = Integer.parseInt(JOptionPane.showInputDialog("How many items are sold in this transaction?"));
//Start Billing Process
String[] itemName = new String [numItems]; //Holds items' respective names
double[] itemPrice = new double [numItems]; //Holds items' respective prices
double runningTotal = 0.0;
for (int a = 0; a < numItems; a++){
itemName[a] = JOptionPane.showInputDialog("Enter the item's name:");
itemPrice[a] = Double.parseDouble(JOptionPane.showInputDialog("Enter " + itemName[a] + "'s price:"));
runningTotal += itemPrice[a];
}
//File naming
Date dateSaleWithName = new Date();
String dateOnReceipt = String.format("ddMMyyyy", dateSaleWithName);
String receiptName = customerName + dateOnReceipt;
File file = new File(receiptName); //For output
PrintWriter sale = new PrintWriter(file);
sale.print(theName + "\n" + theAddress + "\n\n");
sale.print(customerName + "\n" + customerStreet + "\n" + customerCity + ", " + customerST + " " + customerZIP);
sale.print("\n\nItem name\t\tItem Price\n");
for (int i = 0; i < numItems; i++){
sale.print(itemName[i] + "\t\t" + itemPrice[i] + "\n");
}
if (useTax == 1){
double taxAmount = runningTotal * theTax;
sale.print("\nSales Tax\t\t" + runningTotal + "\n");
double trueTotal = runningTotal + taxAmount;
sale.print("Total\t\t" + trueTotal);
//Recording Tax expense
expenseName[y-1] = "Sales Tax - " + receiptName;
expenseValue[y-1] = taxAmount;
y++;
}
else{
sale.print("Total\t\t" + runningTotal);
}
//Recording in System
revenueName[x-1] = receiptName;
revenueValue[x-1] = runningTotal;
}
else{
//This procedure does NOT collect customer information.
numItems = Integer.parseInt(JOptionPane.showInputDialog("How many items are sold in this transaction?"));
//Start Billing Process
String[] itemName = new String [numItems]; //Holds items' respective names
double[] itemPrice = new double [numItems]; //Holds items' respective prices
double runningTotal = 0.0;
for (int a = 0; a < numItems; a++){
itemName[a] = JOptionPane.showInputDialog("Enter the item's name:");
itemPrice[a] = Double.parseDouble(JOptionPane.showInputDialog("Enter " + itemName[a] + "'s price:"));
runningTotal += itemPrice[a];
}
//File naming
Date dateSaleWithoutName = new Date();
String dateOnReceipt = String.format("ddMMyyyy HH:mm:ss", dateSaleWithoutName);
String receiptName = dateOnReceipt;
File file = new File(receiptName); //For output
PrintWriter sale = new PrintWriter(file);
sale.print(theName + "\n" + theAddress + "\n\n");
sale.print("\n\nItem name\t\tItem Price\n");
for (int i = 0; i < numItems; i++){
sale.print(itemName[i] + "\t\t" + itemPrice[i] + "\n");
}
if (useTax == 1){
double taxAmount = runningTotal * theTax;
sale.print("\nSales Tax\t\t" + runningTotal + "\n");
double trueTotal = runningTotal + taxAmount;
sale.print("Total\t\t" + trueTotal);
//Recording Tax expense
expenseName[y-1] = "Sales Tax - " + receiptName;
expenseValue[y-1] = taxAmount;
y++;
}
else{
sale.print("Total\t\t" + runningTotal);
}
//Recording in System
revenueName[x-1] = receiptName;
revenueValue[x-1] = runningTotal;
}
x++;
}
else if (opSelection == 2){
//Expense Reporting
expenseName[y - 1] = JOptionPane.showInputDialog("Enter the name for incurred Expense:");
expenseValue[y - 1] = Double.parseDouble(JOptionPane.showInputDialog("Enter the value for the incurred Expense:"));
y += 1;
}
else {
//End-of-Day(EOD) Procedures
Date date = new Date();
String dateForFile = String.format("MM-dd-yyyy", date);
File file = new File (dateForFile);
PrintWriter outputFile = new PrintWriter(dateForFile);
outputFile.print(theName + "\n");
outputFile.print("\n" + dateForFile + "\n");
//Revenue Recording Procedure
outputFile.print("Revenue Name\t\tRevenue Value\n");
for (int r = 0; r < x; r++){
outputFile.print(revenueName[r] + "t\\t" + revenueValue[r] + "\n");
totalRevenue += revenueValue[r];
}
outputFile.print("Total Revenue:\t\t" + totalRevenue + "\n\n");
//Expense Recording Procedure
outputFile.print("Expense Name\t\tExpense Value\n");
for (int e = 0; e < y; e++){
outputFile.print(expenseName[e] + "\t\t" + expenseValue[e] + "\n");
totalExpense += expenseValue[e];
}
outputFile.print("Total Expense:\t\t" + totalExpense + "\n\n\n");
//Record Document Footer
outputFile.print("\tTotal Revenue:\t" + totalRevenue + "\n");
outputFile.print("\tTotal Expenses:\t" + totalExpense + "\n");
netIncome = totalRevenue - totalExpense;
if (netIncome > 0){
outputFile.print("\tToday's Net Gain\t" + netIncome);
}
else if (netIncome < 0){
outputFile.print("\tToday's Net Loss\t" + netIncome);
}
else{
//This section should never execute, but it is here on the off chance that it needs to.
outputFile.print("\tToday's Yield:\t" + netIncome);
}
return;
}
}
public static void main(String[] args) {
launch(args);
}
}