0

I was trying to build a database project in JavaFX using a scene builder. Everything worked fine with designing, creating CSS files and installing derby database library. But when I run the program, I get the error:

> 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$1(LauncherImpl.java:182)
>   at java.lang.Thread.run(Thread.java:748) Caused by:
> java.lang.UnsupportedClassVersionError:
> org/apache/derby/jdbc/EmbeddedDriver has been compiled by a more
> recent version of the Java Runtime (class file version 53.0), this
> version of the Java Runtime only recognizes class file versions up to
> 52.0  at java.lang.ClassLoader.defineClass1(Native Method)    at java.lang.ClassLoader.defineClass(ClassLoader.java:756)  at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
>   at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)     at
> java.net.URLClassLoader.access$100(URLClassLoader.java:74)    at
> java.net.URLClassLoader$1.run(URLClassLoader.java:369)    at
> java.net.URLClassLoader$1.run(URLClassLoader.java:363)    at
> java.security.AccessController.doPrivileged(Native Method)    at
> java.net.URLClassLoader.findClass(URLClassLoader.java:362)    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:418)     at
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)     at
> java.lang.ClassLoader.loadClass(ClassLoader.java:351)     at
> java.lang.Class.forName0(Native Method)   at
> java.lang.Class.forName(Class.java:264)   at
> db.db.Createconnection(db.java:34)    at db.db.<init>(db.java:27)     at
> javafxapplication3.FXMLDocumentController.initialize(FXMLDocumentController.java:36)
>   at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)    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
> javafxapplication3.JavaFXApplication3.start(JavaFXApplication3.java:22)
>   at
> com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
>   at
> com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
>   at
> com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
>   at java.security.AccessController.doPrivileged(Native Method)   at
> com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
>   at
> com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
>   at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)  at
> com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
>   ... 1 more Exception running application
> javafxapplication3.JavaFXApplication3 Java Result: 1

By searching for similar problems, I found that I might be missing something called VM option(though I am not quite sure, what is that)

So I added this line in my VM option from netbeans project:

--module-path C:\javafx-sdk-11.0.2\lib --add-modules javafx.controls,javafx.fxml

This time I got a new error:

**

Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. The program will exit. Unrecognized option: --module-path Java Result: 1

Now I don't have any clue how to get rid of it.

I have in total of 4 files in my simple project. The main function is here:

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

This is the XML document controller:

@FXML
private Label label;
@FXML
private Button button;

private void handleButtonAction(ActionEvent event) {
    System.out.println("You clicked me!");
    label.setText("Hello World!");
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
     db dbh = new db();
}    

@FXML
private void pri(ActionEvent event) {
    System.out.print("hi");
}

This is the code for creating connection with database:

public db()
{
    Createconnection();
    setupbooktable();
}
void Createconnection()
{
    try
    {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        conn=DriverManager.getConnection(db_url);

    }
    catch(Exception e)
            {
                e.printStackTrace();
            }
}

void setupbooktable()
{

    String tablename="Book";
    try
    {
        stam=conn.createStatement();
        DatabaseMetaData dmd=conn.getMetaData();
        ResultSet tables=dmd.getTables(null, null, tablename.toUpperCase(), null);
        if(tables.next())
        {
            System.out.println("Table"+tablename+"exists already!Ready to go!!");

        }
        else
        {
            stam.execute("CREATE TABLE"+tablename+"("
                    + "id varchar(200) primary key ,\n"
                    + "title varchar(200),\n"
                    + "author varchar(200),\n"
                    + "publisher varchar(200),\n"
                    + "intcode varchar(200),\n"
                    + "isavailable boolean default true"
                    +")");



        }




    }
    catch(SQLException e)
    {
        System.err.printf(e.getMessage()+"error in database...");

    }
    finally
    {

    }

}


I have no issues in importing packages. This project just prints a message on the prompt when the button is pressed. And try to create a database table.

Thanks.

James_D
  • 201,275
  • 16
  • 291
  • 322
  • 2
    Post the complete stack trace. An `InvocationTargetException` just means there was some exception that occurred while invoking another method: you need to know what that underlying exception was. See https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors The `--module-path` option only applies to Java 9 and later: you are using Java 8, so the posts you found are not relevant to your error. – James_D Mar 26 '20 at 14:04
  • James_D I have edited the question –  Mar 26 '20 at 14:34
  • I think your problem stems from this specific line > >org/apache/derby/jdbc/EmbeddedDriver has been compiled by a more > recent version of the Java Runtime (class file version 53.0), this > version of the Java Runtime only recognizes class file versions up to 52 This means that the library you are using was made for java9 not java8 you either need to update your runtime to 9 or find an older version of the library – Austin Mar 26 '20 at 14:37
  • 1
    The problem is here: `java.lang.UnsupportedClassVersionError: org/apache/derby/jdbc/EmbeddedDriver has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0`. The version of Derby (the Java embedded database) you are using is compatible only with Java 9 and later; you are using Java 8. Either upgrade your version of Java, or find a legacy version of Derby compatible with Java 8. – James_D Mar 26 '20 at 14:38
  • java naming conventions, please! – kleopatra Mar 26 '20 at 15:28
  • Thanks a lot! Actually the problem was in derby version. I downgraded(!) it,and it worked :D –  Mar 27 '20 at 06:27

0 Answers0