Q:

How do I load in an FXML URL for my JavaFX program?

I am currently following the Jenkov tutorial for JavaFX. He wrote the following code
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.net.URL;

public class FXMLExample extends Application{

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(new URL("file:///C:/data/hello-world.fxml"));
        VBox vbox = loader.<VBox>load();

        Scene scene = new Scene(vbox);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

This is my version of what he wrote:
package sample;

import javafx.application.Application;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.net.URL;

//import java.awt.*;

public class Main extends Application {

    // The start method takes a single parameter of type stage.
    // The stage is where all the visual parts of the application are displayed
    // The stage is created
    @Override
    public void start(Stage primaryStage) throws Exception{
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(new URL("home/amnar/IdeaProjects/mockUI/src/sample/sample.fxml"));
        VBox vbox = loader.<VBox>load();

        Scene scene = new Scene(vbox);
        primaryStage.setTitle("My first JavaFX app");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

Now when I try to run this I get errors with the following stack trace:
Gtk-Message: 13:44:10.402: Failed to load module "canberra-gtk-module"
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$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.MalformedURLException: no protocol: \home\amnar\IdeaProjects\mockUI\src\sample\sample.fxml
    at java.net.URL.<init>(URL.java:593)
    at java.net.URL.<init>(URL.java:490)
    at java.net.URL.<init>(URL.java:439)
    at sample.Main.start(Main.java:24)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
    ... 1 more
Exception running application sample.Main

Process finished with exit code 1

I am aware of the gtk error and I am not sure whether or not it is causing the issue. I am running ubuntu 18.04.01 LTS on my machine with budgie as a desktop environment. I found out that the gtk error is caused by something with the default install being 32 bits while my machine is 64 bits. I tried to fix the issue to no avail. Nonetheless, when I try to run a JavaFX example without having to use an FXML file it works fine even though the error is still there.
What am I missing here? Do I have to do something different because I am running linux while the example seems to be run on windows? I've seen various other ways of importing the FXML such as using getClass()... etc. Again, I would get this huge stack trace which I don't understand. It seems that the critical section of the trace is this:
Caused by: java.net.MalformedURLException: no protocol: \home\amnar\IdeaProjects\mockUI\src\sample\sample.fxml

Hence I assume that I need to reformat the URL and I don't know what to do.
Thanks!

A:

You have properly recognized your problem. Java's URL class needs to have specified protocol. Try this out:
loader.setLocation(new URL("file:///home/amnar/IdeaProjects/mockUI/src/sample/sample.fxml"));

