I coded a button in my project to trigger a method that generates multiple anchor panes on a parent anchor pane and displays database information on the label nodes in each of the generated anchor panes. This button works sometimes and other times This error triggers seemingly at random. This is the error:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
It points to no specific line in my application at all just internal classes in java. I have checked my code and cannot find any methods that aren't getting the right argument data types related to this code.
public void generateMultiAnchorPanes(AnchorPane pane) {
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setFitToHeight(true);
VBox vbHolder = new VBox();
vbHolder.setFillWidth(true);
List<Integer> listIDs = new ArrayList<>();
listIDs = StaffData.retrieveAllEmployeeIDs();
System.out.println("the list of IDs" + listIDs);
double topOffset = 0.0;
for (int i : listIDs) {
AnchorPane innerAnchorPane = createAnchorPane(i);
innerAnchorPane.setPadding(new Insets(5)); // Add padding around the AnchorPane
AnchorPane.setTopAnchor(innerAnchorPane, topOffset);
AnchorPane.setLeftAnchor(innerAnchorPane, 10.0);
innerAnchorPane.setStyle("-fx-background-color: #FFFFFF;");
topOffset += 180.0; // Increase the offset for the next row
vbHolder.getChildren().add(innerAnchorPane);
}
scrollPane.setContent(vbHolder);
AnchorPane.setTopAnchor(scrollPane, 0.0);
AnchorPane.setLeftAnchor(scrollPane, 0.0);
AnchorPane.setRightAnchor(scrollPane, 0.0);
AnchorPane.setBottomAnchor(scrollPane, 0.0);
pane.getChildren().add(scrollPane);
}
This code is for making the anchor panes. and this is the createAnchorPane method code:
private AnchorPane createAnchorPane(int EmployeeID){
AnchorPane innerAnchorPane = new AnchorPane();
VBox outerVBox = createVBox(EmployeeID);
innerAnchorPane.getChildren().addAll(outerVBox);
return innerAnchorPane;
}
This then is code for the outerVBox creation
private VBox createVBox(int EmployeeID) {
String[] names = StaffData.retrieveName(EmployeeID);
boolean clockedIn = StaffData.getClockedIn(EmployeeID);
boolean transIsActive = StaffData.isTransActive(EmployeeID);
double globalStaffAverageTrans[] = StaffData.getLIfetimeAverageTransTime(EmployeeID);
String formattedAverageInMins = String.format("%.0f", globalStaffAverageTrans[0]);
double LiveTransAverage[] = StaffData.getLiveAverageTransTime(EmployeeID);
String formattedAverageInDeconds = String.format("%.0f", LiveTransAverage[0]);
String strTimeInCompany = StaffData.getYearsMonthsDaysWorkingString(EmployeeID);
String strTotalAmountOfTransactions = StaffData.StaffTransactionTotal(EmployeeID);
Font font = Font.font("Arial", 15);
Font fontSubHeading = Font.font("Calisto MT", 15);
VBox outerVBox = new VBox();
Image image = new Image("/Images/EmployeeIcon.jpg");
// Calculate the maximum dimensions to fit the image within the screen
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
double maxWidth = screenBounds.getWidth() * 0.15; // 80% of screen width
double maxHeight = screenBounds.getHeight() * 0.15; // 80% of screen height
// Create an ImageView and set the image with proportional resizing
ImageView imageView = new ImageView(image);
imageView.setPreserveRatio(true);
imageView.setFitWidth(maxWidth);
imageView.setFitHeight(maxHeight);
HBox employeeTitle = new HBox();
employeeTitle.setSpacing(20);
employeeTitle.setAlignment(javafx.geometry.Pos.CENTER);
employeeTitle.setPrefWidth(884);
employeeTitle.setPrefHeight(50);
employeeTitle.setStyle("-fx-background-color: #00A2D3;");
Label lblEmployeeName = new Label(names[0]+ " " + names[1]);
lblEmployeeName.setFont(font);
Label lblEmployeeIDDisplay = new Label("Employee ID: " + String.valueOf(EmployeeID));
lblEmployeeIDDisplay.setFont(font);
employeeTitle.getChildren().addAll(imageView, lblEmployeeName, lblEmployeeIDDisplay);
VBox alignmentBox = new VBox();
Label lblClockedIn = new Label();
Label lblIsTramsActive = new Label();
Label lblAmountOfTranactionToday = new Label();
Label lblAverageTransactionTime = new Label();
if (clockedIn && transIsActive){
strClockedIn = "Clocked In";
lblClockedIn.setTextFill(Color.GREEN);
strTransIsActive = "Transaction Active";
lblIsTramsActive.setTextFill(Color.GREEN);
}
else if (clockedIn == true && transIsActive == false){
strClockedIn = "Clocked In";
lblClockedIn.setTextFill(Color.GREEN);
strTransIsActive = "Transaction Not Active";
lblIsTramsActive.setTextFill(Color.RED);
}
else {
strClockedIn = "Not Clocked In";
lblClockedIn.setTextFill(Color.RED);
strTransIsActive = "Transaction Not Active";
lblIsTramsActive.setTextFill(Color.RED);
}
lblClockedIn.setText(strClockedIn);
lblIsTramsActive.setText(strTransIsActive);
if (LiveTransAverage[0] > globalStaffAverageTrans[0]){
lblAverageTransactionTime.setTextFill(Color.RED);
}
else if (LiveTransAverage[0] == globalStaffAverageTrans[1] && LiveTransAverage[1] > globalStaffAverageTrans[1]){
lblAverageTransactionTime.setTextFill(Color.RED);
}
else {
lblAverageTransactionTime.setTextFill(Color.GREEN);
}
lblAmountOfTranactionToday.setText("Transactions Today: " + StaffData.getTodaysTransactionsStaff(EmployeeID));
lblAverageTransactionTime.setText("Live Average Transaction Time: " + formattedAverageInDeconds + "mins " + LiveTransAverage[1] + "secs");
HBox employeeLiveData = new HBox();
employeeLiveData.setSpacing(20);
employeeLiveData.setStyle("-fx-background-color: #FF9900;");
employeeLiveData.setPrefHeight(30);
employeeLiveData.setPrefWidth(895);
employeeLiveData.getChildren().addAll(lblClockedIn, lblIsTramsActive, lblAmountOfTranactionToday,lblAverageTransactionTime);
HBox HBOrganiser = new HBox();
HBOrganiser.setSpacing(50);
Label lblUsefulData = new Label("Useful Statistics");
lblUsefulData.setFont(fontSubHeading);
GridPane usefulData = new GridPane();
usefulData.setHgap(20); // Horizontal gap between cells
usefulData.setVgap(20); // Vertical gap between cells
usefulData.setStyle("-fx-background-color: #FFFFFF;");
Label lengthOfTimeWorking = new Label();
Label lblLifeTimeAverageTransTime = new Label();
Label lblTotalAmountTransactions = new Label();
Label lblTotalPaymentFromStart = new Label();
Label lblGlobalStaffTransAverage = new Label();
Label lblSickDaysTaken = new Label("Cell (2, 1)");
lengthOfTimeWorking.setText("Time in Company: " + strTimeInCompany);
lblTotalAmountTransactions.setText("Total Transactions: " + strTotalAmountOfTransactions);
lblGlobalStaffTransAverage.setText("Lifetime Averaage Transaction Time: " + formattedAverageInMins + "mins " + globalStaffAverageTrans[1] + "sec");
// Adding labels to the GridPane at specific positions
usefulData.add(lengthOfTimeWorking, 0, 0);
usefulData.add(lblLifeTimeAverageTransTime, 0, 1);
usefulData.add(lblTotalAmountTransactions, 1, 0);
usefulData.add(lblTotalPaymentFromStart, 1, 1);
usefulData.add(lblGlobalStaffTransAverage, 2, 0);
usefulData.add(lblSickDaysTaken, 2, 1);
VBox.setMargin(employeeLiveData, new Insets(0, 0, 10, 10)); // Add some left margin
VBox.setMargin(HBOrganiser, new Insets(10, 0, 0, 10)); // Add some left margin
outerVBox.setAlignment(Pos.CENTER_RIGHT);
HBOrganiser.getChildren().addAll(lblUsefulData, usefulData);
alignmentBox.getChildren().addAll(employeeLiveData, HBOrganiser);
HBox imageOrganiser = new HBox();
imageOrganiser.getChildren().addAll(imageView, alignmentBox);
outerVBox.getChildren().addAll(employeeTitle, imageOrganiser);
return outerVBox;
}
these labels are being populated by database methods from another class that all take the argument of employeeid. This is its use in the FXMLController java class part of the application:
@FXML
public void switchScene(ActionEvent event){
if (event.getSource() == btnDashboard){
anchDashboard.setVisible(true);
anchAccounts.setVisible(false);
anchManageUsers.setVisible(false);
anchStaff.setVisible(false);
anchStatistics.setVisible(false);
anchTimetable.setVisible(false);
lblTitle.setText("Dashboard");
}
else if (event.getSource() == btnTimetable) {
anchDashboard.setVisible(false);
anchAccounts.setVisible(false);
anchManageUsers.setVisible(false);
anchStaff.setVisible(false);
anchStatistics.setVisible(false);
anchTimetable.setVisible(true);
lblTitle.setText("Timetable");
}
else if (event.getSource() == btnStaff){
anchDashboard.setVisible(false);
anchAccounts.setVisible(false);
anchManageUsers.setVisible(false);
anchStaff.setVisible(true);
anchStatistics.setVisible(false);
anchTimetable.setVisible(false);
lblTitle.setText("Staff");
SPB.generateMultiAnchorPanes(anchStaff);
}
}
else if (event.getSource() == btnManageUsers){
anchDashboard.setVisible(false);
anchAccounts.setVisible(false);
anchManageUsers.setVisible(true);
anchStaff.setVisible(false);
anchStatistics.setVisible(false);
anchTimetable.setVisible(false);
lblTitle.setText("Manage Users");
}
else if (event.getSource() == btnStatistics){
anchDashboard.setVisible(false);
anchAccounts.setVisible(false);
anchManageUsers.setVisible(false);
anchStaff.setVisible(false);
anchStatistics.setVisible(true);
anchTimetable.setVisible(false);
lblTitle.setText("Statistics");
}
else if (event.getSource() == btnAccounts){
anchDashboard.setVisible(false);
anchAccounts.setVisible(true);
anchManageUsers.setVisible(false);
anchStaff.setVisible(false);
anchStatistics.setVisible(false);
anchTimetable.setVisible(false);
lblTitle.setText("Accounts");
}
}
This is the XML code for the button:
<Button fx:id="btnStaff" blendMode="LIGHTEN" mnemonicParsing="false" onAction="#switchScene" style="-fx-background-color: #363232;" text="Staff" textFill="#7c8184">
<graphic>
<FontIcon iconColor="WHITE" iconLiteral="fas-users" iconSize="21" />
</graphic></Button>
This also an example of my retrieval methods used in outerVBox creation.
public static boolean isTransActive(int employeeID){
boolean blnTransisActive = false;
try (Connection conn = JDBConnection.getConnection()) {
PreparedStatement stmt = conn.prepareStatement("SELECT TRANSISACTIVE FROM TBLTRANSACTION WHERE EMPLOYEEID =?");
stmt.setInt(1, employeeID); // Bind the employeeID parameter
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
blnTransisActive = rs.getBoolean("TRANSISACTIVE");
}
} catch (SQLException e) {
e.printStackTrace();
}
This is the stack trace of the error:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1852)
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8792)
at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)
at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3897)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1878)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2623)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:557)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:943)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:829)
So I first printed what the StaffData.retrieveAllEmployeeIDs() was returning and that was not the error returns correct values. I think it might be the acnhor pane anchstaff that's causing the problem because whenever I get the error if i got into scene builder and stretch the size of anchStaff it starts to work again as intended until but when I try closing and running the application multiple times and pressing the staff button the original exception gets thrown.
I appreciate any help anyone can offer in possible solutions or any theories of what the error could be. Thank you.