Error invoking method при запуске javafx

I'm developing a desktop application using javafx v8.0.40. I have created an exe file with inno 5. When I run exe file in my computer, it is installed and run without any problem. On the other hand...

I’m developing a desktop application using javafx v8.0.40. I have created an exe file with inno 5. When I run exe file in my computer, it is installed and run without any problem. On the other hand, when I try to install and run it on some other computer, at the end of installation, window dialog pops up: «Error invoking method», I click Ok. Another window pop up saying «Failed to launch jvm». I searched the whole internet, but I couldn’t find much about this topic. I hope I will get solution to this problem.
Thank you in advance.

asked Oct 22, 2015 at 15:43

tarlan's user avatar

tarlantarlan

1711 gold badge1 silver badge5 bronze badges

3

I ran into the same problem; the following worked for me and helped me make sense of those blasted «Error invoking method.» and «Failed to launch JVM» dialogs:

  1. Find your .jar file
    • It has the same name as your Project and it’s in your application’s installation directory under AppDataLocal{ApplicationTitle}app (shortcut: type %appdata% into explorer); if your project was named HelloWorld, there you will find HelloWorld.jar
  2. Navigate to it’s directory in command prompt
    • shift+Right Click any blank spot in the Explorer window and choose «Open command window here» (that’s a fancy trick I recently learned; alternatively you would cd to the same directory using the command prompt)
  3. Run your .jar via the command line
    • type java -jar "HelloWorld.jar" and hit Enter

Tadah! Behold your hidden exceptions (the existence of which «Error invoking method.» so vaguely tries to communicate to you). *

If your problem is similar to mine it stems from a file structure difference between the project out folder and the installation directory, and that’s why the program compiles just fine in the editor and builds just fine—there isn’t a problem until it’s built out, and the file structure is a little different.

*If you didn’t get anything when you ran it via the command line, look for any errors that could be happening during that initialize() method; that’s where your problem likely is. You can expose any exceptions during runtime by using a Popup Exception Dialog like shown in a similar problem, here.

Community's user avatar

answered Jul 1, 2016 at 22:20

Brad Turek's user avatar

Brad TurekBrad Turek

2,3722 gold badges30 silver badges55 bronze badges

1

This is probably because it lacks the dependencies in the output jar. So you need to add the libraries in the artifact and then .exe generation should be ok.

Here is an example with Intellij, where the libraries have be manually moved from «Available Elements» to the artifact

Intellij example

svarog's user avatar

svarog

9,3174 gold badges62 silver badges77 bronze badges

answered Feb 3, 2016 at 14:03

Rumoch's user avatar

RumochRumoch

611 silver badge5 bronze badges

even though this question is a little old — today I faced the exact same problem and couldn’t find any solution searching for those error messages other then here.

The problem is pretty much identically:
Built JavaFX Application (running fine on dev pc) using java 8 and packaged to native installer (exe) using Inno 5.
Application ran fine on some of our machines — on others it failed with exact those to error messages:

  • «Error invoking method»
    and after clicking OK
  • «Failed to launch jvm».

On application startup, the fxml loader loads the first view controller and calls its «initialize» method. If — within initialize — an unhandeled exception is being thrown, the application crashes and those two windows error messages are shown.

Hope that this will help some one who like me is struggling with that, too.

answered Jun 8, 2016 at 9:58

J.Dürr's user avatar

The response by J.Dürr (answered Jun 8 ’16 at 9:58) helped solve my Error invoking method & Failed to launch JVM issue. I used the following code to track down the issue, which turned out to be an errant FXML resource path:

public static void main(final String[] taArgs)
{
  try
  {
    Main.launch(taArgs);
  }
  catch (Exception e)
  {
    JOptionPane.showMessageDialog(null, e.getMessage());
    try
    {
      PrintWriter pw = new PrintWriter(new File("<somefilename.txt>"));
      e.printStackTrace(pw);
      pw.close();
    }
    catch (IOException e1)
    {
      e1.printStackTrace();
    }
  }
}

answered Oct 10, 2017 at 21:36

Eddie Fann's user avatar

I just had this issue and @Brad Turek’s answer pointed me at the right direction. Except it wasn’t my code that throw the exception.

The .cfg file (at /<app_name>/app/<app_name>.cfg) that the .exe wrapper used to start my application had incorrectly pointed to libs (jar files) that didn’t exist at the /lib directory. Which (I concluded) caused the classloader to throw and terminate the startup.

After correcting the .cfg file everything worked fine.

answered Mar 6, 2019 at 10:17

svarog's user avatar

svarogsvarog

9,3174 gold badges62 silver badges77 bronze badges

I could not fix the problem, but I found a way around it. I used notepad to create a batch file to launch the app. First I used cd to get to the directory of the .jar file and then used java -jar to launch the app. It should look something like this:

cd C:[wherever your project folder is located][name of project]dist
java -jar [name of project].jar

Save it as a .bat file on the desktop, launch the batch file and your program will boot!

answered Aug 17, 2018 at 4:45

Bold Warrior's user avatar

You could experience this error if you didn’t include the third-party libraries to the build.

The following can be placed in the build.xml just before the end tag of the project.

<target name="-post-jfx-deploy">
    <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" nativeBundles="all"
               outdir="${basedir}/${dist.dir}" outfile="${application.title}">
        <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
        <fx:resources>
            <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>       
            <fx:fileset dir="${basedir}/${dist.dir}" includes="lib/*.jar"/>
        </fx:resources>
        <fx:info title="${application.title}" vendor="${application.vendor}"/>
    </fx:deploy>           

answered Feb 19, 2020 at 22:47

Yaw's user avatar

YawYaw

1561 silver badge4 bronze badges

I figured it out!

The way I found the problem:

After double, triple checking the dependencies and seeing that it both compiled and then built fine, I suspected the jar file which is located at build/deploy/{yourProjectName}.jar

EDIT: If you’re getting the errors only once it is installed, it makes sense to run the jar in the installation directory. ( AppData/Local/{ApplicationTitle}/app/{yourProjectName}.jar )

I ran it on the command line to see if it was throwing an exception:

To easily navigate to the directory I noted where I had saved my project in Explorer and then copied that to the command line.

  1. Open command prompt

    Win + r

    cmd + Enter

  2. Navigate to the directory

    cd {ProjectPath}builddeploy

  3. Run the jar file

    java -jar "{YourJar}.jar"

Because I executed the jar via the command prompt, java had somewhere to show me the exception!

C:Usersadministrator.SUNDANCEIdeaProjectsPODTester_Layout8builddeploy>java
 -jar "PODTester_Layout8.jar"
java.io.FileNotFoundException: srcresourcesCarrier List.txt (The system cannot
 find the path specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileReader.<init>(Unknown Source)

Upon reviewing my code, I figured that it wasn’t finding the file because of the explicit reference to src. I fixed that and lo and behold! Upon rebuilding, the installed application worked!


So in summary:

If your native package throws you a

Error invoking method.

and a

Failed to launch JVM

run your jar file via the command prompt to see if it throws exceptions.


Now if you want details about my specific problem and the process I went through to fix it, here you go:

The Problem:

I thought it might’ve been something to do with dependencies (especially with me including the sqljdbc driver), but it turns out it wasn’t a dependency issue. The problem was that the .jar was throwing an exception only once installed. What made the error so hard to understand was the oh-so-generic «Could not invoke method.» which gave me little new information.

To mitigate future similar problems I added a showExceptionDialog() method (inspired by Marco Jacob’s work) :

/**
 * Shows a dialog box when an exception occurs instead of just doing nothing.
 *
 * Once installed this will help to diagnose problems instead of letting
 * them go unnoticed.
 *
 * @param e the exception to print; it's stacktrace will be shown as well
 */
public static void showExceptionDialog(Exception e) {
    Alert alert = new Alert(Alert.AlertType.ERROR);

    alert.setTitle("Exception Dialog");
    alert.setHeaderText("An error occurred:");

    String content = "Error: ";
    if (null != e) {
        content += e.toString() + "nn";
    }

    alert.setContentText(content);

    Exception ex = new Exception(e);

    //Create expandable Exception.
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);

    String exceptionText = sw.toString();

    //Set up TextArea
    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);


    textArea.setPrefHeight(600);
    textArea.setPrefWidth(800);


    //Set expandable Exception into the dialog pane.
    alert.getDialogPane().setExpandableContent(textArea);


    alert.showAndWait();
}

Specific details about my problem:

In my program I had a file called Carrier List.txt being read and written to, and it was stored in the resources folder.

In IntelliJ and Eclipse it compiled just fine because it could find src/resources/Carrier List.txt just fine. Things would have been just fine when I manually copied the resources folder as per Marco Jacob’s Deployment Tutorial, but I explicitly referenced

src/resources/Carrier List.txt

in my code instead of just

resources/Carrier List.txt

Содержание

  1. Error invoking method, Failed to launch JVM. (UPDATE: Program crashes if game is installed on non-default disk) #9
  2. Comments
  3. Error invoking method. Failed to launch JVM #380
  4. Comments
  5. Basic Info
  6. Description
  7. Log File (optional)
  8. Error invoking method failed to launch jvm
  9. JavaFX application fail to launch with native exe bundle created with intellij ide #173
  10. Comments
  11. gse-demo Error invoking method / Failed to launch JVM #13
  12. Comments

Error invoking method, Failed to launch JVM. (UPDATE: Program crashes if game is installed on non-default disk) #9

I was getting these errors when trying to launch the program, so I ran it through a CMD and it outputs this.

Checking for Dark Souls install.
Checking for custom Steam Library directory.
Checking Registry for Dark Souls install.
Checking game version.
Exception in Application start method
java.lang.reflect.InvocationTargetException
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 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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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(Unknown Source)
Caused by: java.lang.NullPointerException
at dscfgutil.view.DSCfgMainUI.checkDSVersion(DSCfgMainUI.java:1428)
at dscfgutil.view.DSCfgMainUI.checkForDS(DSCfgMainUI.java:1369)
at dscfgutil.view.DSCfgMainUI.initWindow(DSCfgMainUI.java:430)
at dscfgutil.view.DSCfgMainUI.initUI(DSCfgMainUI.java:384)
at dscfgutil.view.DSCfgMainUI.(DSCfgMainUI.java:376)
at dscfgutil.DSCfgUtil.start(DSCfgUtil.java:30)
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.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
. 1 more
Exception running application dscfgutil.DSCfgUtil

The text was updated successfully, but these errors were encountered:

Источник

Error invoking method. Failed to launch JVM #380

Basic Info

  • I’m running Cryptomator on: Windows 7 6.1
  • I’m using Cryptomator in version: 1.2.0

Description

I get immediately after starting:
Error invoking method. Failed to launch JVM

Log File (optional)

[?:1.8.0_102] at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:153)

[?:1.8.0_102] at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:82)

[commons-httpclient-3.1.jar:?] at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:127)

[commons-httpclient-3.1.jar:?] at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)

[commons-httpclient-3.1.jar:?] at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)

[commons-httpclient-3.1.jar:?] at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)

[commons-httpclient-3.1.jar:?] at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)

[commons-httpclient-3.1.jar:?] at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)

[commons-httpclient-3.1.jar:?] at org.cryptomator.ui.controllers.WelcomeController.lambda$checkForUpdates$0(WelcomeController.java:110)

[Cryptomator-1.2.0.jar:1.2.0] at org.cryptomator.ui.util.AsyncTaskService.lambda$asyncTaskOf$0(AsyncTaskService.java:32)

[Cryptomator-1.2.0.jar:1.2.0] at org.cryptomator.ui.util.AsyncTaskService$AsyncTaskImpl.lambda$null$6(AsyncTaskService.java:89)

[Cryptomator-1.2.0.jar:1.2.0] at org.cryptomator.ui.util.AsyncTaskService.logExceptions(AsyncTaskService.java:118)

[Cryptomator-1.2.0.jar:1.2.0] at org.cryptomator.ui.util.AsyncTaskService.access$100(AsyncTaskService.java:19)

[Cryptomator-1.2.0.jar:1.2.0] at org.cryptomator.ui.util.AsyncTaskService$AsyncTaskImpl.lambda$run$7(AsyncTaskService.java:87)

[Cryptomator-1.2.0.jar:1.2.0] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

[?:1.8.0_102] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

[?:1.8.0_102] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_102]»>

The text was updated successfully, but these errors were encountered:

Me too .

Basic Info

  • I’m running Cryptomator on: Windows Server 2012 R2 6.3 (amd64)
  • I’m using Cryptomator in version: 1.2.0

Description

I get immediately after starting:
Error invoking method. Failed to launch JVM

Источник

Error invoking method failed to launch jvm

Would it be okay to ask you to ping me on Skype, and we can perhaps work through whatever issue you might be having? Seems like something new.
I’m Daniel.Garfield1

I’m also getting the same issue.

Using Windows 10 — 64 Bit
16 GB Ram
Intel i7-7700HQ CPU
NVIDIA GeForce GTX 1050 Ti and Intel HD Graphics 630 (built in).

I’ve updated Java, which was a pain in it’s own regards cause Windows 10 doesn’t like to work well with others.

For anyone who encounters this in the future, FYI: No need to update Java, as the game uses a bundled in JVM. So, your computer’s installation is unlikely to matter.

If anyone does want to hit me up on Skype, though, I’d love to solve this with someone in realtime.
Getting some meaningful debug output would help a lot.

Thanks very much to DapperPrinny, I have a workaround on this, albeit not a fix.
I’m currently reaching out to Valve for more information on this to pursue and easier solution.

For now, this seems to work:
1) Navigate to C:Program Files (x86)SteamsteamappscommonMetronomiconMetronomicon
2) Create a file called steam_appid.txt
3) Open that file, and paste, on the first line, just this: 416790
4) Save and close.
5) In that folder, there is an EXE. Double-click to run the game.

This should give you the exact same game/content as running it from steam would. I’m not sure yet why launching it directly From steam is failing (especially on just a small minority of machines), but I’m escalating that to Valve now.
A bit of a pain, but the game is fully functional, hooray!

Hm, possibly you’re having some other additional issue?
If you wouldn’t mind reaching out to me on Skype (Daniel.Garfield1), I’d love to debug with you in real time, if you’re up for it.

The same error to me, i created the txt archive with this ID and didn’t work, i transform into a .dll and didn’t work too.

My computer configuration:

OS: Windows 10 32 bits
ram: 3GB DDR3
CPU: Intel core 2 Duo 3.1Ghz
Video card: dedicated

I update the java version to 8, i newbie (maybe junior) in java development, would be the version? if a do i downgrade to 6.x or 7.x the game works? or is a error on calling the method?

Thanks for cooperation, i love this game!

The java version that the game uses is bundled in, so your local installation shouldn’t matter. Though, as a common thread, I’m starting to suspect it might.

I’m going to do some investigation, but if you wouldn’t mind helping, you can reach me on Skype at Daniel.Garfield1. I’d love to run some tests with you.

Update: After further research, it looks like this MAY have been introduced in Java 8, in the packaging code (which is something I cannot fix). However, the fix appears to be rolled out in Java 8, which is not easily compatible to this project.

A workaround which I BELIEVE will work appears to be:
1) Open a command prompt.
2) CD into C:Program Files (x86)SteamsteamappscommonMetronomiconMetronomiconapp
3) Create a file called steam_appid.txt
4) Open that file, and paste, on the first line, just this: 416790
5) Save and close.
6) Type: java -jar Metronomicon.jar to launch the game.

Note that I haven’t tried this, as the issue only happens on a smallish number of machines. But, based on what I’m reading, I believe that this MIGHT work.
Further note: This does require that Java be installed in advance.

Источник

JavaFX application fail to launch with native exe bundle created with intellij ide #173

I have build a JavaFX application which can be executed by its jar file. However if i try to run it using the native exe bundle i am receiving two popups:

Error Invoking method

Failed to launch JVM

and the application fails to start.

The Javafx application is build with intellij ide.

The config file looks as:-
[Application]
app.name=firecap
app.mainjar=firebase_product_listener.jar
app.version=1.0
app.preferences.id=firebase_product_listener_id
app.mainclass=firebase/product/listener/Main
app.classpath=lib/animal-sniffer-annotations-1.18.jar;lib/annotations-4.1.1.4.jar;lib/api-common-1.9.2.jar;lib/auto-value-annotations-1.7.2.jar;lib/checker-compat-qual-2.5.5.jar;lib/commons-codec-1.11.jar;lib/commons-lang3-3.5.jar;lib/commons-logging-1.2.jar;lib/conscrypt-openjdk-uber-2.2.1.jar;lib/error_prone_annotations-2.3.4.jar;lib/failureaccess-1.0.1.jar;lib/firebase-admin-6.16.0.jar;lib/fontawesomefx-8.9.jar;lib/gax-1.57.0.jar;lib/gax-grpc-1.57.0.jar;lib/gax-httpjson-0.74.0.jar;lib/google-api-client-1.30.10.jar;lib/google-api-client-gson-1.30.10.jar;lib/google-api-services-storage-v1-rev20200430-1.30.9.jar;lib/google-auth-library-credentials-0.20.0.jar;lib/google-auth-library-oauth2-http-0.20.0.jar;lib/google-cloud-core-1.93.6.jar;lib/google-cloud-core-grpc-1.93.6.jar;lib/google-cloud-core-http-1.93.6.jar;lib/google-cloud-firestore-1.35.0.jar;lib/google-cloud-storage-1.110.0.jar;lib/google-http-client-1.35.0.jar;lib/google-http-client-appengine-1.35.0.jar;lib/google-http-client-gson-1.36.0.jar;lib/google-http-client-jackson2-1.36.0.jar;lib/google-oauth-client-1.31.0.jar;lib/grpc-alts-1.30.0.jar;lib/grpc-api-1.30.0.jar;lib/grpc-auth-1.30.0.jar;lib/grpc-context-1.30.0.jar;lib/grpc-core-1.30.0.jar;lib/grpc-grpclb-1.30.0.jar;lib/grpc-netty-shaded-1.30.0.jar;lib/grpc-protobuf-1.30.0.jar;lib/grpc-protobuf-lite-1.30.0.jar;lib/grpc-stub-1.30.0.jar;lib/gson-2.8.6.jar;lib/guava-29.0-android.jar;lib/httpclient-4.5.12.jar;lib/httpcore-4.4.13.jar;lib/j2objc-annotations-1.3.jar;lib/jackson-core-2.11.0.jar;lib/javax.annotation-api-1.3.2.jar;lib/jsr305-3.0.2.jar;lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;lib/mysql-connector-java-5.1.49.jar;lib/netty-buffer-4.1.50.Final.jar;lib/netty-codec-4.1.50.Final.jar;lib/netty-codec-http-4.1.50.Final.jar;lib/netty-common-4.1.50.Final.jar;lib/netty-handler-4.1.50.Final.jar;lib/netty-resolver-4.1.50.Final.jar;lib/netty-transport-4.1.50.Final.jar;lib/opencensus-api-0.24.0.jar;lib/opencensus-contrib-grpc-util-0.24.0.jar;lib/opencensus-contrib-http-util-0.24.0.jar;lib/perfmark-api-0.19.0.jar;lib/proto-google-cloud-firestore-admin-v1-1.35.0.jar;lib/proto-google-cloud-firestore-v1-1.35.0.jar;lib/proto-google-cloud-firestore-v1beta1-0.88.0.jar;lib/proto-google-common-protos-1.18.0.jar;lib/proto-google-iam-v1-0.13.0.jar;lib/protobuf-java-3.12.2.jar;lib/protobuf-java-util-3.12.2.jar;lib/slf4j-api-1.7.25.jar;lib/slf4j-api-1.7.30.jar;lib/slf4j-jdk14-1.7.30.jar;lib/threetenbp-1.4.4.jar
app.runtime=$APPDIRruntime
app.identifier=firebase_product_listener_id

The packaged jar file is executing properly. the problem occurs when starting application with launching exe file. kindly tell me what could went wrong?

The text was updated successfully, but these errors were encountered:

Источник

gse-demo Error invoking method / Failed to launch JVM #13

Do you want to request a feature or report a bug?
bug?

What is the current behavior?

Issue with javafx tutorial when trying to build and run the native app:

$ mvn clean package
$ ./target/jfx/native/gse-demo/gse-demo
gse-demo Error invoking method.
gse-demo Failed to launch JVM

But then it seems to work after clearing, rebuilding and launching a second time:

rm -r -f ./target/
mvn clean package
./target/jfx/native/gse-demo/gse-demo

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Following the steps of the javafx-packager tutorial:

$ git clone https://github.com/powsybl/powsybl-tutorials.git
$ cd powsybl-tutorials/javafx-packager
$ mvn clean package
$ ./target/jfx/native/gse-demo/gse-demo
gse-demo Error invoking method.
gse-demo Failed to launch JVM

Please tell us about your environment:

  • PowSyBl Version: powsybl-gse 1.3.0; powsybl-core 2.3.0
  • OS Version: Kubuntu 18.04.2 LTS

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, spectrum, etc)

(if a question doesn’t apply, you can delete it)

The text was updated successfully, but these errors were encountered:

Источник

Comments

@jaysudodeveloper

Im working on a windows based machine and running the jfxNative task generates the files okay i think but when running the executable i get the bellow error popup.

Im doing nothing special other than using the minimal gradle build

image

@FibreFoX

What happens when you run the jfx-jar from CLI? Mostly there are some unhandled exceptions or missing libs.

@jaysudodeveloper

This seems to be an issue for building the app on my linux box as well but running just the jar from command line gives:

jacques@Flatbread:~/Documents/GitHub/linesmarts-desktop/build/jfx/native/linesmarts-desktop-1.0-SNAPSHOT/app (master)$ ./project-jfx.jar 
com.linesmarts.model.ModelManager@4f28d398

No exceptions, same output for both windows and linux.

gradle file:

group 'com.linesmarts'
version '1.0-SNAPSHOT'

buildscript {
    dependencies {
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
    }
    repositories {
        mavenLocal()
        mavenCentral()

    }
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'javafx-gradle-plugin'

mainClassName = 'com.linesmarts.Main'
repositories {
    mavenLocal()
    mavenCentral()
}

jfx {
    // minimal requirement for jfxJar-task
    mainClass = 'com.linesmarts.Main'

    // minimal requirement for jfxNative-task
    vendor = 'linesmarts'
}

edit: I do get these warnings sorry

Aug 18, 2017 6:55:54 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 8.0.111 by JavaFX runtime of version 8.0.60
Aug 18, 2017 6:55:54 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 8.0.111 by JavaFX runtime of version 8.0.60

@FibreFoX

Please execute your jfx-jar via java -jar, otherwise there is too much magic. The warning about the API-value might be ignorable, just a warning (but not related to this gradle-plugin).

Can you try to remove this line?

apply plugin: 'application'

It’s not required when using this gradle-plugin, as you are not creating an application, but an javafx-bundle

@jaysudodeveloper

jay@blackbox:~/Documents/GitHub/linesmarts-desktop (master) $ java -jar build/jfx/native/linesmarts-desktop-1.0-SNAPSHOT/app/project-jfx.jar
Aug 18, 2017 10:22:54 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 8.0.111 by JavaFX runtime of version 8.0.60
Aug 18, 2017 10:22:55 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 8.0.111 by JavaFX runtime of version 8.0.60
com.linesmarts.model.ModelManager@60961404

Same output running with java -jar

Ive attached the project in it’s current state with the changes mentioned above. The JAR runs fine it seems just not any of the native stuff. Im 100% sure its not my platform as ive cloned your sample projects and they all work fine even with having fxml files for views. My project doesnt differ in terms of directory structure.

linesmarts-desktop.zip

@FibreFoX

I can reproduce this on Windows, maybe I can find this piece of trouble ;)

@FibreFoX

Can you try to change the following code:

    public static void main(String[] args) {
        WindowManager.setModelManager( getEmptyModelManager() );
        launch( args );
    }

Please move WindowManager.setModelManager( getEmptyModelManager() ); away from the main method, after that the binary worked for me …. strange.

After moving this call into the start(Stage stage)-method seems to work for me.

@jaysudodeveloper

Can you try to change the following code:

public static void main(String[] args) {
    WindowManager.setModelManager( getEmptyModelManager() );
    launch( args );
}

Please move WindowManager.setModelManager( getEmptyModelManager() ); away from the main method, after that the binary worked for me …. strange

Where did you move it to? Because now im getting slightly different error now.

jay@blackbox:~/Documents/GitHub/linesmarts-desktop/build/jfx/native/linesmarts-desktop-1.0-SNAPSHOT (master) $ sudo ./linesmarts-desktop-1.0-SNAPSHOT
[sudo] password for jay: 
linesmarts-desktop-1.0-SNAPSHOT Class com/linesmarts/Main not found.
linesmarts-desktop-1.0-SNAPSHOT Failed to launch JVM

@FibreFoX

In that «Main»-class, I moved that line to the start() method … maybe your code differs from the stuff you attached here?

@jaysudodeveloper

Please move WindowManager.setModelManager( getEmptyModelManager() ); away from the main method, after that the binary worked for me …. strange.

After moving this call into the start(Stage stage)-method seems to work for me.

Ok moving that call to start() method fixes issues for windows and now runs fine. Only fails on linux build now with this error still:

jay@blackbox:~/Documents/GitHub/linesmarts-desktop/build/jfx/native/linesmarts-desktop-1.0-SNAPSHOT (master) $ sudo ./linesmarts-desktop-1.0-SNAPSHOT
[sudo] password for jay: 
linesmarts-desktop-1.0-SNAPSHOT Class com/linesmarts/Main not found.
linesmarts-desktop-1.0-SNAPSHOT Failed to launch JVM

@FibreFoX

Did you clean the «build»-folder? Maybe it’s some recompile-issue? ;)

@jaysudodeveloper

Did you clean the «build»-folder? Maybe it’s some recompile-issue? ;)

Did a full clean and jfxNative build and still same issue.

@FibreFoX

Thats odd. What JDK are you using on your systems? It seems that your Windows- and your Linux-system do not have the same version.

@jaysudodeveloper

jay@blackbox:~ $ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
jay@blackbox:~ $ javac -version
javac 1.8.0_131
jay@blackbox:~ $ 

@jaysudodeveloper

jay@blackbox:~ $ java -version
openjdk version «1.8.0_131»
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
jay@blackbox:~ $ javac -version
javac 1.8.0_131
jay@blackbox:~ $

So this is weird, my desktop(Linux) is the only one that does not properly build the app for linux native. I took the same repo i linked earlier and built it on my laptop with the other change you recommended and it build fine and runs.

I suppose you can close the issue now but im still unsure why it doesnt build on my desktop.

@FibreFoX

Okay, will close this issue. If you find something, just drop some lines so others can find it via search.

But yes, it really is strange that there is a different behaviour.

@thekalinga

I’m facing exactly the same issue in Ubuntu 16.04

My java version is

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Any idea on how to resolve this issue?

Fix JavaFx Exception in Application Start Method

JavaFX is a highly enriched library whose code gets written in native Java code. The library gets used to making Rich Internet Applications, often known as RIA.

The library is a set of interfaces and classes that are easily understandable and are a friendly alternative to Java Virtual Machine or JVM. The code written using the library can run across multiple platforms without fail like desktops, mobiles, televisions, etc.

Long back, the graphical User Interface gets built using Swing templates, but after the advent of JavaFX, one can easily rely on the language to work over the same. The applications built using JavaFx have a penetration rate of 76 percent.

The Exception in Application start method is the runtime error that occurs when the application is running and when compilation gets done. The state occurs when the application is inefficient in loading runtime variables or files. It can throw NullPointerException, FileNotFound type of exceptions when not handled properly.

Additionally, plugins like SonarLint, programming mistake detector(PMD), find bugs can help identify the runtime issues beforehand without actual program runs.

Below is an example to show the Exception in Application start method error in JavaFx.

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

public class ApplicationStart extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Parent parent = FXMLLoader.load(getClass().getResource("AnyXML.fxml"));
        Scene scene = new Scene(parent);
        stage.setScene(scene);
        stage.setTitle("First Swing Sample");
        stage.show();
    }
}

The above source code that seems to be in JavaFx has a main method in the ApplicationStart class. The given class extends an abstract Application class and is specifically available in JavaFX Library.

It has a default theme called Caspein that gets launched once you start the application. The launch is a static method present in the Application class and gets called from the main function. It takes variable arguments or varargs as its parameters. It throws IllegalStateException if the launch method gets called more than once.

The Application class has one abstract method whose implementation must be present in ApplicationStart class. The override annotation shows that the code below the annotation belongs to the parent Application class. The implementation of the method that gets proceeded by the annotation override is present below the annotation.

The start method is the main entry for the JavaFX applications, as main is the entry location for the Java applications. The main method gets first called when the Application or main thread gets initialized.

The function takes Stage as the parameter. The Stages denotes the primary step or view and gets loaded when the application launches in the applet viewer. It also throws Exception that gets defined along with the method.

The first statement inside the method is to load the XML file. The FXMLLoader class loads an object hierarchy from the XML object model. It gets used to bring the object hierarchy from an FXML document into a Parent instance. It takes the parameter as the URL to the location where the XML document hierarchy is present.

The resultant gets stored in a Parent class instance that holds the subtypes in the graph format. The Scene class present in the JavaFX library is the container unit that stores all the data in a graph view. The background of the scene gets filled by the specified property. The instance of Stage class gets created and can get used with other properties.

Below mentioned are the properties used to display the scene over the browser.

  • The setScene method makes its use to specify the scene and gets used along with the stage instance variable.
  • The setTitle function gets used to set scene title present over the browser. The show function gets used to populate the scene over the stage.

Below is the output for the above code block.

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:873)
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.NullPointerException: Location is required.
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
	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 ApplicationStart.start(ApplicationStart.java:15)
	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$3(WinApplication.java:177)
	... 1 more
Exception running application ApplicationStart

In the output shown above, the issue gets raised at the parameter position that uses the FXMLLoader class to load the XML object, but it returns a null value. In simple words, the getResource() method does not locate the path provided in the function parameter.

Hence, the null value populates NullPointerException, which is a type of runtime exception. And are handled by giving an absolute path where the file can get located. The stack trace often shows the line number where the issue starts populating. The target must be correct when get given in the load parameter.

Hence the given solution to the problem is below.

  1. Give the absolute path to the location where the file gets present.
  2. Add a SonarLint plugin to the Integrated Development Environment that helps in evaluating or handling the exceptions at the write time.

Why exception in java lang reflect invocationtargetexception is happeningThe exception in application start method java.lang.reflect.InvocationTargetException is an error code that occurs when you are using JavaFX. There are myriad situations that cause this error. Keep on reading, as we’ll give you detailed explanations of these causes and their fix.

By the end of this article, you’ll know how to prevent and fix the error in your future JavaFX projects.

Contents

  • Why Exception in Java.lang.reflect.invocationtargetexception is Happening?
    • – Having a Starting Forward Slash in the Pathname of Your Fxml File
    • – Missing Javafx Modules
    • – Using Dynamic Root Without Setting the Root on the Fxmlloader
  • How To Fix the Exception in Application Error?
    • – Remove the Forward Slash in the Path Name of the Fxml File
    • – Update Intellij Idea To Use Javafx Modules Via the vm Options
    • – Set the Root on Fxmlloader Before Loading the Fxml File
  • Conclusion

You have an exception in java.lang.reflect.InvocationTargetException because of the following:

  • You have a starting forward slash in the pathname of your FXML file
  • You are missing JavaFX modules
  • You are using dynamic root without setting the root on the FXMLLoader

– Having a Starting Forward Slash in the Pathname of Your Fxml File

A forward slash in the pathname of your FXML file can cause an exception in JavaFX. For example, the following code can trigger the exception:

FXMLLoader loader = new FXMLLoader(Main.class.getResource(“/File.fxml”));

When you check the previous code, you’ll note that we have a forward slash before the FXML file. Though this will work on some systems, but on most systems, it’ll cause an exception.

– Missing Javafx Modules

Missing JavaFX modules when running JavaFX can cause an exception. The “Getting Started with JavaFX” on OpenJFX outlined steps for a JavaFX project with IntelliJ IDEA. Check the below points:

  • Create a JavaFX project
    • At this stage, you give your project a name
    • Give the project a location
  • Set JDK 17
    • You do this by navigating to File → Project Structure → Project
    • Also, you can set the language level to a minimum value of 11
  • Create a library
    • Navigate to File → Project Structure → Libraries
    • Add JavaFX 17 SDK as a library
    • Point to the lib folder of the SDK
      • Once you apply the library, IntelliJ will recognize the JavaFX classes

If you perform all the operations outlined in the previous steps, your code will compile but you’ll get an error. That’s because IntelliJ does not include some modules that’ll make your code work. For the code to work, you have to tell Java which modules it’ll use for your application.

Keep on reading, as we’ll explain how you can fix this in the “How To Fix” section.

– Using Dynamic Root Without Setting the Root on the Fxmlloader

You’ll raise an exception if you use the dynamic root <fx:root type=”AnchorPane”> without setting the root on the FXMLLoader. That’s because < fx:root> specifies a dynamic root for your FXML file. So, its root is an object that you must set before loading the FXML file. Meanwhile, a use case for this is when you want to define the layout of custom controls with FXML.

For example, an exception occurs in the following public class. This class extends the Application class in JavaFX:

public class HelloWorld extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource(“MyFXMLDoc.fxml”));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}

In the above-mentioned code, we’ve called the load() method of FXMLLoader on the FXML file but we did not set any root before trying to load the FXML file. As a result, the code causes an exception.

How To Fix the Exception in Application Error?

You can fix the exception by updating your code or adding the required JavaFX modules. As a result, your code will work as expected. However, it’s easier said than done. In this section, we’ll go into detail on how to fix and prevent the exception in your project.

– Remove the Forward Slash in the Path Name of the Fxml File

When you load your FXML file with FXMLLoader, observe if there is a forward slash in the pathname of the FXML file. If you are getting an exception, remove this forward slash. Afterward, your code should work. For example, the following is a code we showed you earlier:

FXMLLoader loader = new FXMLLoader(Main.class.getResource(“/File.fxml”));

From the code, we have the forward slash before File.fxml but in the code below, we’ve eliminated the forward slash. So, your code should work.

// Take out the “/” before the FXML file

FXMLLoader loader = new FXMLLoader(Main.class.getResource(“File.fxml”));

There are cases where the absence of the forward slash caused an exception. So, if you are in such a situation, add the forward slash to prevent the exception.

– Update Intellij Idea To Use Javafx Modules Via the vm Options

In IntelliJ IDEA, you’ll need to add the JavaFX modules as a VM option based on your Operating System. We say “JavaFX modules” because JavaFX is a collection of modules. We base this solution on the “Getting Started” tutorial on OpenJFX. Earlier, we mentioned that if you compile your code without the JavaFX modules, you’ll get an error.

To add the VM options, go to the following location in IntelliJ IDEA:

Run → Edit Configurations

At the above location, if you are on Windows, add the VM options using the following:

–module-path “pathtojavafx-sdk-17.0.1lib” –add-modules javafx.controls,javafx.fxml

If you are on Linux or Mac, use the following:

–module-path /path/to/javafx-sdk-17.0.1/lib –add-modules javafx.controls,javafx.fxml

As an alternative, you can define a global variable for future projects. To get started, navigate the following path in IntelliJ:

  1. Preferences (File → Settings) → Appearance & Behavior → Path Variables
  2. Define the variable name as PATH_TO_FX
  3. Browse to the lib folder of the JavaFX SDK to set its value
  4. Click apply

Afterward, you can refer to this global variable when you set the VM options:

–module-path ${PATH_TO_FX} –add-modules javafx.controls,javafx.fxml

Once you’ve added the VM options, run your project, and your code should work fine.

The project created on the OpenJFX tutorial is the default project that uses FXML therefore, your code requires javafx.fxml and javafx.controls. Note that if your project uses other modules, you should add them. So, after adding the modules, save your settings.

– Set the Root on Fxmlloader Before Loading the Fxml File

To prevent the exception, you should set the root on FXMLLoader before you load your FXML file. The next code block is a sample class that we discussed earlier. In the code, we did not set the root before loading the FXML file. As a result, we get an error.

public class HelloWorld extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource(“MyFXMLDoc.fxml”)); // Where the error occurred
Scene scene = new Scene(root);
stage.setScene(scene); stage.show();
}
}

However, in our next code, we’ve made corrections. The corrections ensure the proper use of <fx:root> which are the following:

  • Create an FXMLLoader instance
  • Call setRoot() on the instance
    • Pass in the root object of the FXML

public class HelloWorld extends Application {
@Override
public void start(Stage stage) throws Exception {
// Create an FXMLLoader Instance
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(“MyFXMLDoc.fxml”));
// Call setRoot on the instance
fxmlLoader.setRoot(new AnchorPane());
// Call the load() function on the file
Parent root = fxmlLoader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}

Conclusion

This article explained how to fix the causes of the exception when you are using JavaFX. We provided coding examples and explained solutions with actionable steps to identify and solve the issue. Here are the summary of the most important points that we talked in the article:

  • A starting forward slash in the path name of an FXML file can cause an exception.
  • Not setting the root before loading the XML file leads to an exception.
  • To prevent an exception when working with JavaFX in IntelliJ, use JavaFX modules.
  • You can add JavaFX modules as VM options in IntelliJ IDEA.
  • You can prevent the failure from happening by setting the root on FXMLLoader before you load your FXML file.

How to fix the exception in application errorAt this stage, you have what it takes to fix the exception in your application and run an error-free code.

  • Author
  • Recent Posts

Position is Everything

Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.

Position is Everything

Понравилась статья? Поделить с друзьями:
  • Error invoking method перевод
  • Error invoking method jlss exe
  • Error invoking method failed to launch jvm
  • Error invalidregistration fcm
  • Error invalidfont offendingcommand xshow