0

I am trying to create a basic window with a couple of tabs in the middle, with the first tab containing a table.

Each time I run the main java class it gives me errors, even when I get rid of table and tabs.

Here is my main file:

package application;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.fxml.FXMLLoader;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

Here is my fxml file:

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

<?import com.gluonhq.charm.glisten.control.NavigationDrawer?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<BorderPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application/SampleController.java">
   <left>
      <GridPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1280.0" BorderPane.alignment="CENTER">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="580.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints maxHeight="81.0" minHeight="60.0" prefHeight="60.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="152.0" minHeight="60.0" prefHeight="60.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="420.0" minHeight="420.0" prefHeight="420.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="315.0" minHeight="180.0" prefHeight="180.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" GridPane.columnIndex="1" GridPane.rowIndex="2">
              <tabs>
                <Tab text="Untitled Tab 1">
                  <content>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                           <children>
                              <TableView editable="true" layoutX="109.0" layoutY="47.0" prefHeight="200.0" prefWidth="200.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                <columns>
                                  <TableColumn prefWidth="75.0" text="C1" />
                                  <TableColumn prefWidth="75.0" text="C2" />
                                </columns>
                              </TableView>
                           </children>
                        </AnchorPane>
                  </content>
                </Tab>
                <Tab text="Untitled Tab 2">
                  <content>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                  </content>
                </Tab>
              </tabs>
            </TabPane>
            <NavigationDrawer GridPane.columnIndex="1" GridPane.rowIndex="3" />
         </children>
      </GridPane>
   </left>
</BorderPane>

Anything helps. I couldn't find anything on this, but possible it's my fxmlloader.load file source? I really don't know.

Here is my error code:

javafx.fxml.LoadException: 
/C:/Users/_____/Desktop/AllJava/Java/SecAnalyzer/bin/application/Sample.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.importClass(Unknown Source)
    at javafx.fxml.FXMLLoader.processImport(Unknown Source)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:14)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.NavigationDrawer
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at javafx.fxml.FXMLLoader.loadTypeForPackage(Unknown Source)
    at javafx.fxml.FXMLLoader.loadType(Unknown Source)
    ... 21 more

NEW ERROR after installing gluon mobile:

javafx.fxml.LoadException: 
/C:/Users/____/Desktop/AllJava/Java/SecAnalyzer/bin/application/Sample.fxml:14

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.access$700(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(Unknown Source)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(Unknown Source)
    at javafx.fxml.FXMLLoader$Element.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:14)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: application/SampleController.java
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 23 more
StealthVice7
  • 95
  • 12

1 Answers1

0

Do you have NavigationDrawer.class in your classpath?

Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.NavigationDrawer

In your FXML file you have:

<?import com.gluonhq.charm.glisten.control.NavigationDrawer?>

So you need to haveNavigationDrawer.class in yourclasspath to properly load the FXML document.

If you do not you need to download it from gluonhq.

jpell
  • 163
  • 1
  • 10
  • Try removing NavigationDrawer from scenebuilder / fxml and see if it works. – jpell Oct 01 '17 at 03:46
  • I am really confused? gluohq is scenebuilder. I have that. – StealthVice7 Oct 06 '17 at 23:55
  • @StealthVice7 When you build things with scenebuilder it calls the Node's constructor. Since Gluon took over scenebuilder they added some of their own nodes/classes. However you still need to have the classes on your classpath to use them. It is misleading I agree. Just like using controlsFX library you need to have it in both scenebuilder and on your classpath to use it not just one. – jpell Oct 07 '17 at 00:02
  • If you are using Netbeans, go to plugins and download the Gluon mobile plugin and install it. – SedJ601 Oct 07 '17 at 00:04
  • I'm sorry I am so confused. I already have e(fx)clipse downloaded, and scenebuilder linked to eclipse. I can open scene builder and it edits my fxml. I followed a youtube tutorial exactly. Why doesn't it work? And what exactly else do I need to do? Thanks – StealthVice7 Oct 07 '17 at 00:37
  • Think about it like this... TextField tf = new TextField(); You have the TextFeld class in your classpath by default with java8+. But you do not have NavigationDrawer.class in your classpath by deafult; therefore Java has no clue what a NavigationDrawer is. So when your program loads the FXML doucment it throws ClassNotFoundException. – jpell Oct 07 '17 at 00:49
  • So I installed gluohq mobile thing into eclipse, still doesn't work, same error it seems. Also something weird is it forced me to get rid of e(fx)clipse to install mobile. – StealthVice7 Oct 07 '17 at 01:20
  • download and add this .jar to your project build path "charm-glisten4.4.0.jar" http://nexus.gluonhq.com/nexus/content/repositories/releases/com/gluonhq/charm-glisten/4.4.0/ – jpell Oct 07 '17 at 01:25
  • Did that, added to build path. Still spits out a bunch of errors for me. – StealthVice7 Oct 07 '17 at 02:01
  • Just added the new error after installing gluhq mobile – StealthVice7 Oct 14 '17 at 00:46
  • @StealthVice7 your problem is here: Caused by: java.lang.ClassNotFoundException: application/SampleController.java...check the fx:controller in scenebuilder – jpell Oct 14 '17 at 00:49
  • package application; public class SampleController { } That is all my SampleController is. – StealthVice7 Oct 14 '17 at 00:55
  • Where do I check fx:controller in scenebuilder? – StealthVice7 Oct 14 '17 at 00:57
  • @StealthVice7 left side lowest titled pane or "menu list bar" under "controller" – jpell Oct 14 '17 at 00:58
  • It says it is : application.SampleController – StealthVice7 Oct 14 '17 at 01:04
  • @StealthVice7 remove ".java" from your fx:controller – jpell Oct 15 '17 at 15:38
  • Not sure what you mean. My fx:controller = application.SampleController. Where is ".java"? – StealthVice7 Oct 15 '17 at 22:58
  • @StealthVice7 not its not... in your fxml file you have "fx:controller="application/SampleController.java">" remove the .java – jpell Oct 15 '17 at 22:59
  • Oh damn, for some reason the one I have pasted above is .java, but I guess I was trying to fix whatever and it is application/Samplecontroller on my computer. With or without .java it still gives me errors. – StealthVice7 Oct 15 '17 at 23:14
  • Have you tried running my code? Does it work? Is it just a "me" thing? – StealthVice7 Oct 15 '17 at 23:14
  • Yeah works for me are you creating this for mobile or desktop use? – jpell Oct 15 '17 at 23:15
  • Desktop use. Maybe it's something that I haven't installed correctly? – StealthVice7 Oct 15 '17 at 23:17
  • Don't use moblie layouts for desktop application s. Does it work without the navigation drawer? – jpell Oct 15 '17 at 23:18
  • Is it maybe my file structure? Like where I have my files in my project folder? Also saw your newest reply, navigation drawer? – StealthVice7 Oct 15 '17 at 23:18
  • Oh wow. Yeah I deleted navigation drawer, and even though its awfully offcentered it doesnt give me errors anymore! what is navigation drawer? Also you said I was developing for mobile? How do I make it for desktop? – StealthVice7 Oct 15 '17 at 23:27
  • It was the mobile layout that you were trying to implement in your fxml file. – jpell Oct 15 '17 at 23:27
  • Mobile layout? How do i "un-mobile" my layout? – StealthVice7 Oct 15 '17 at 23:28
  • Like for a phone don't use the controls / layouts highlighted as blue in scenebuilder those are for mobile application s. – jpell Oct 15 '17 at 23:29
  • Thanks a lot, I didn't even know that SceneBuilder had controls and layouts specifically intended for mobile use and that that screws with the result. (although I would have thought it would still work... - also confused on what navigation drawer is - is it only for mobile too? If not wont I run into the same problem?) Thanks a lot for your help! – StealthVice7 Oct 15 '17 at 23:34
  • Yeah not sure what someone would use it but yes it is for moblie applications. – jpell Oct 15 '17 at 23:35