-1

Thank you all, issue wasn't related to the file load, but to a different part of the code. Sorry for wasing your time, but thank you anyways!

The git link: https://github.com/TomerShenkar/PhoneProjectV3

I've seen this question here before but whenever I try to fix my problem it doesn't work.

When trying to load a new window in java fxml, I use this method:

public void openContacts(ActionEvent event) {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("/application/CV.fxml"));
        Scene scene = new Scene(root);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.show();
    }
    catch(Exception e) {
        System.out.println(e);
    }
}

But I get this excpetion:

javafx.fxml.LoadException: 
/C:/Users/tomer/eclipse-workspace/PhoneProj%20V3/bin/application/CV.fxml

Any help? Thanks!

Edit: full error message

javafx.fxml.LoadException: 
/C:/Users/tomer/git/phoneProjV3/PhoneProjV3/bin/application/CV.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
    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 application.MainController.openContacts(MainController.java:240)
    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)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java: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$353(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at application.MainController.initialize(MainController.java:51)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 66 more

FXML File

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.CVController">
   <children>
      <Button layoutX="481.0" layoutY="75.0" mnemonicParsing="false" onAction="#fillCM" text="Search" />
      <TextField fx:id="tf" layoutX="325.0" layoutY="75.0" />
      <Button layoutX="325.0" layoutY="141.0" mnemonicParsing="false" onAction="#placeCall" text="Call" />
      <Button layoutX="367.0" layoutY="141.0" mnemonicParsing="false" text="Text" />
      <Button layoutX="412.0" layoutY="141.0" mnemonicParsing="false" text="Edit" />
      <Button layoutX="325.0" layoutY="174.0" mnemonicParsing="false" text="Delete" />
      <Button layoutX="381.0" layoutY="174.0" mnemonicParsing="false" text="Create" />
      <ComboBox fx:id="cmBox" layoutX="77.0" layoutY="73.0" prefHeight="28.0" prefWidth="223.0" />
      <Label layoutX="231.0" layoutY="20.0" prefHeight="28.0" prefWidth="149.0" text="Contacts View">
         <font>
            <Font size="20.0" />
         </font>
      </Label>
   </children>
</AnchorPane>

Someone suggested changing the project name and removing the space, didn't do anything... I also tried giving the full path name of the file, instead of just "/application/CV.fxml". (full path name is"C:\Users\tomer\eclipse-workspace\PhoneProjV3\src\application\CV.fxml")

  • 1
    Please [edit] your question to include the _full_ [stack trace](https://stackoverflow.com/questions/3988788/). – Slaw Jan 18 '19 at 16:18
  • When you edit also post the folder structure. – c0der Jan 18 '19 at 16:30
  • Some expression yielding `null` is dereferenced in MainController.java, line 51 – fabian Jan 18 '19 at 18:12
  • Note that a `LoadException` is likely not the real problem. Are there any `Caused by`s? – Slaw Jan 18 '19 at 18:36
  • @Slaw I am getting a caused by for a ComboBox load (even though it fills up just fine) – Tomer Shenkar Jan 18 '19 at 18:44
  • Can you show your `MainController` and comment which line is line `51`? – Slaw Jan 18 '19 at 18:46
  • @Slaw initializing the combobox did the trick. I guess I missed it when I wrote the code for the first time. – Tomer Shenkar Jan 18 '19 at 18:48
  • Looking at your GitHub repo, you have `@FXML public ComboBox comboBox;` but in your FXML file you have `fx:id="cmBox"`. The names must match for the `FXMLLoader` to inject the instance. – Slaw Jan 18 '19 at 18:51
  • Nope, initializing the `comboBox` field simply fixes the symptoms, but it does not solve the real issue (= using a `fx:id` for the `` element that does not match the field name you're trying to inject to). BTW: The question in it's current state is still off topic, since we require the necessary info to be contained in the question itself (; a link is insufficient). At least part of `MainController` would be required to be part of the question to change this. – fabian Jan 18 '19 at 18:52
  • I'm using two comboBoxs in two different classes. The one in MainController matches the one in Main.fxml (It is used to load comm ports). The comboBox in CV.fxml is used to display names from a sql database. I didn't notice these issues, and because of that I thought the issue was in the file load. Sorry guys, this is all new to me. – Tomer Shenkar Jan 18 '19 at 18:57

1 Answers1

-1

Try to remove the space in the project name. The "PhoneProj V3" gets urlencoded which results in "PhoneProj%20V3" and that resulting name doesn't exist.

Try to change "PhoneProj V3" to "PhoneProjV3" (remove the space).

kai
  • 894
  • 1
  • 7
  • 15
  • javafx.fxml.LoadException: /C:/Users/tomer/eclipse-workspace/PhoneProjV3/bin/application/CV.fxml Doesn't seem to change anything... – Tomer Shenkar Jan 18 '19 at 16:49
  • At least one problem less ;) I spot another, there is a slash at the beginning that imho doesn't belong there. Also you've forward slashes on Windows - which shouldn't be a problem but it is not the standart fileseparator for windows. Is it possible, that you are working on some mixed linux/windows envuronment? Linux subsystem or something like that? – kai Jan 18 '19 at 17:02
  • if you try to give the path directly and it works, there is something wrong with OS/Eclipse configuration. You can paas for the test the path like this; FXMLLoader loader = new FXMLLoader(new File("C:\Users\tomer\eclipse-workspace\PhoneProjV3\bin\application\CV.fxml").toURI().toURL()) – kai Jan 18 '19 at 17:29
  • 1
    It's completely normal that a URL a) encodes spaces as `%20` b) uses slashes instead of backslashes (even for file urls). Also it's `FXMLLoader` that leaves out the protocol. – fabian Jan 18 '19 at 17:41
  • @Fabian Well i'f say Windows can't find the file with the displayed path - right? Also the Java code is trivial enough and looks fine. So why can't it find the file if not for some problem with the path? – kai Jan 18 '19 at 18:02
  • 1
    No, you got confused by the op's question title. The fact that `getResource` did not return `null` is a indicator that java IS able to find the fxml file. Also the complete stacktrace added to the question by the OP a few minutes ago shows the real issue (which is unrelated to the path). – fabian Jan 18 '19 at 18:15
  • @kai I did try to give the full path, with the C:\Users... and it still didn't work. – Tomer Shenkar Jan 18 '19 at 18:29
  • Did you see fabians explanation above? He is right I was focused on the path. Your problem is is unrelated to the path the loader actually succeeds in loading the file correctly. – kai Jan 18 '19 at 18:42