-2

I have several fxml files with corresponding control files. They all work except one. That one used to work. Here is the error log. I am using Netbeans 12.0 beta 2 and Maven. I am also using Scenebuilder. I am using 6 major fxml files. All of them work except browse.fxml.

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.mycompany.kioskapp2.App.loadFXML(App.java:34)
    at com.mycompany.kioskapp2.App.setRoot(App.java:29)
    at com.mycompany.kioskapp2.PrimaryController.BrowseItemsButtonAction(PrimaryController.java:24)

browse.fxml

App.java

public class App extends Application {

    private static Scene scene;
    public static String Username, Password;

    @Override
    public void start(Stage stage) throws IOException {
        scene = new Scene(loadFXML("primary"), 800, 700);
        stage.setTitle("Grogan Vending");
        stage.setScene(scene);
        stage.show();
    }

    static void setRoot(String fxml) throws IOException {
        System.out.println("in setRoot");
        scene.setRoot(loadFXML(fxml));
    }

    private static Parent loadFXML(String fxml) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
        return fxmlLoader.load();
    }

    @SuppressWarnings("empty-statement")
    public static void VerifyUsername(String user, String passwd) throws IOException {
        System.out.println("in App.VerifyUsername");
        Boolean bool1 = false;
        Boolean bool2 = false;
        Boolean found1 = false;
        Boolean found2 = false;
        String savestr = null;
        try {
            try (FileReader reader = new FileReader("C:\\Users\\Skibum.DESKTOP-DBDQH1D\\Documents\\NetBeansProjects\\KioskApp2\\src\\main\\resources\\com\\mycompany\\kioskapp2\\LoginFile.txt")) {
                BufferedReader bufferedReader = new BufferedReader(reader);

                String dbline;

                while ((dbline = bufferedReader.readLine()) != null) {
                    bool1 = dbline.contains(user);
                    if (bool1 == true) {
                        found1 = true;
                        found2 = dbline.contains(passwd);
                        savestr = dbline;
                    }
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        if (found2 == false) {
            App.setRoot("passwderr");
        }
        if (found1 == false) {
            try {
                App.setRoot("usernameerr");
            } catch (IOException ex) {
                Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (found1 == true && found2 == true) {
            String result[] = savestr.split(",");
            for (String temp: result){

            }
            System.out.println(result[2]);
            App.setRoot("primary");
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

PrimaryController.java

public class PrimaryController {

    @FXML private Text actiontarget;

    @FXML private void LoginButtonAction() throws IOException {
        App.setRoot("login");
        System.out.println("Login button pressed");
    }

    @FXML private void NewAccountButtonAction() throws IOException {
        App.setRoot("newaccount");
        System.out.println("New Account button pressed");
    }

    @FXML private void BrowseItemsButtonAction() throws IOException {
        App.setRoot("browse");
        System.out.println("Browse Items button pressed");
    }

    @FXML private void ExpenseAcctButtonAction()throws IOException {
        App.setRoot("expenseacct");
        System.out.println("expense acct button pressed");
    }

    @FXML private void HelpButtonAction()throws IOException {
        App.setRoot("help");
        System.out.println("Help button pressed");
    }

    @FXML private void SuggestButtonAction()throws IOException {
        App.setRoot("suggestions");
        System.out.println("Suggestions button pressed");
    }

}

Stack Trace

    Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
    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:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 48 more
    Caused by: javafx.fxml.LoadException: 
    /C:/Users/Skibum.DESKTOP-DBDQH1D/Documents/NetBeansProjects/KioskApp2/target/classes/com/mycompany/kioskapp2/browse.fxml:16

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:932)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at com.mycompany.kioskapp2.App.loadFXML(App.java:34)
at com.mycompany.kioskapp2.App.setRoot(App.java:29)
at com.mycompany.kioskapp2.PrimaryController.BrowseItemsButtonAction(PrimaryController.java:24)
... 58 more
    Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
... 68 more
  • Post the complete stack trace, including all the "Caused by" clauses. – James_D Jun 01 '20 at 01:22
  • Also please [edit] your question and [format](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks) you code correctly. – James_D Jun 01 '20 at 01:32
  • Tried to post complete stack trace. It said that it was too long. Here are the "Caused by" clauses. – Tim Hofheins Jun 01 '20 at 03:30
  • Caused by: java.lang.reflect.InvocationTargetException – Tim Hofheins Jun 01 '20 at 03:31
  • Caused by: javafx.fxml.LoadException: /C:/Users/Skibum.DESKTOP-DBDQH1D/Documents/NetBeansProjects/KioskApp2/target/classes/com/mycompany/kioskapp2/browse.fxml:16 – Tim Hofheins Jun 01 '20 at 03:32
  • Caused by: java.lang.InstantiationException at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) – Tim Hofheins Jun 01 '20 at 03:33
  • Is there anything else that is needed? – Tim Hofheins Jun 01 '20 at 03:34
  • 1
    [Edit] the question with the complete stack trace, formatted as code. I am not aware of any length restrictions. What you’ve posted is not the *complete* stack trace. – James_D Jun 01 '20 at 03:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215058/discussion-between-tim-hofheins-and-james-d). – Tim Hofheins Jun 01 '20 at 03:37
  • I can’t use chat from the phone app. Please edit the question to 1. Format your code correctly, and 2. Include the complete stack trace. It is not rocket science – James_D Jun 01 '20 at 03:58
  • I tried to include the complete stack trace. For the extra long lines I tried to indent 4 spaces but it wouldn't do it. So I was unable to format it successfully. – Tim Hofheins Jun 01 '20 at 04:04
  • I'm not sure of the specifics, but I believe lower-rep users have more restrictions placed on them regarding the code-to-non-code ratio that's allowed in their question. If you [edit] your question to add the stack trace in "plain text" then I or someone else can come along and properly format it as a code block for you. – Slaw Jun 01 '20 at 07:11
  • This may also help you: [What is a stack trace, and how can I use it to debug my application errors?](https://stackoverflow.com/questions/3988788/). – Slaw Jun 01 '20 at 07:14
  • [mcve] please .. it's an absolute _must_ when seeking debugging help! And mind the __M__ - remove all unrelated, stick to a single item/control, provide controller, application, fxml and complete stack trace. – kleopatra Jun 01 '20 at 09:34
  • Are you sure there isn't more to the stack trace? An `InstantiationException` should typically have a cause. – Slaw Jun 02 '20 at 13:55
  • There is nothing missing in the stack trace. I compared the stack trace in this post with the stack trace in my app and they are the same. – Tim Hofheins Jun 02 '20 at 15:09
  • Weird. If that's the case then I can't deduce the cause of the problem from only the stack trace—it doesn't even tell you _what class_ failed to instantiate. I think you'll need to provide a [mre] demonstrating the problem. – Slaw Jun 04 '20 at 06:45

2 Answers2

0

You are missing the event type is the function's parameters

BrowseItemsButtonAction() 

should be

BrowseItemsButtonAction(MouseEvent event)  
Rashid Iqbal
  • 1,123
  • 13
  • 13
  • 1
    the parameter is optional - if given, it must match the xx of the onXx attribute in the fxml (here most probably not a mouseEvent, impossible to be absolutely certain without seeing the fxml) And please don't replicate the naming violations of the question .. – kleopatra Jun 01 '20 at 09:41
  • I tried BrowseItemsButtonAction(MouseEvent event). It didn't work. All of the other fxml files do not use (MouseEvent event) and they work fine. The execution goes along until App.java attempts to switch control to browse.fxml. That is when the exception is thrown. I made sure that the fx:controller in browse.fxml is set correctly to com.mycompany.kioskapp2.BrowseController. – Tim Hofheins Jun 02 '20 at 00:35
0

I fixed the problem. I was using a static class which wasn't neccessary. I removed the static definition and it worked.