1

I'm kinda new to Java, and I'm trying out JavaFX. I'm using NetBeans 8.2 and made a new JavaFX project. Netbeans created a sample "Hello world" app, but running it gave me this error:

Executing C:\Users\*****\Documents\NetBeansProjects\HelloWorld\dist\run875675325\HelloWorld.jar using platform C:\Program Files\Java\jdk1.8.0_20\jre/bin/java
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:483)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
    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:483)
    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:875)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
    at com.sun.javafx.application.LauncherImpl$$Lambda$48/752848266.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassFormatError: Truncated class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:819)
    at com.sun.javafx.application.LauncherImpl$$Lambda$51/1073159910.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/584634336.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/670904707.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
    at com.sun.javafx.application.PlatformImpl$$Lambda$46/501263526.run(Unknown Source)
    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$141(WinApplication.java:102)
    at com.sun.glass.ui.win.WinApplication$$Lambda$37/96639997.run(Unknown Source)
    ... 1 more
Exception running application helloworld.HelloWorld
Java Result: 1

Any help would be appreciated.

someguy
  • 13
  • 3

1 Answers1

0

The key thing in that stack trace is this line:

Caused by: java.lang.ClassFormatError: Truncated class file

Anything that says Error within a stacktrace points to really severe "environmental" kind of problems.

In your case: it seems that one (or more) of the class files that your IDE generates out of java source code is simply corrupted.

Try to to simple clean and rebuild your project.

If that doesn't help (which I would find rather surprising); then I am kinda worried that your Netbeans installation itself is somehow corrupted (so, me personally, I would then completely wipe that installation and try from scratch again).

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • Hi. I tried to clean and rebuild, but it still gave me the same errors. I didn't modify the code in any way. It's just the sample code that NetBeans generates when you start a new JavaFX Application. – someguy Nov 26 '16 at 20:45
  • 1
    Before re-installing everything, go to project properties and make sure the source format is JDK-8. If that and clean/build doesn't work, you have bigger problems. – brian Nov 26 '16 at 20:54
  • It is set to JDK-8. Guess I'll try reinstalling. – someguy Nov 27 '16 at 04:26
  • So I just installed JDK 8u111 and the errors went away. I'm not sure why, but it seems my previous JDK 1.8.0.20 installation was causing it. – someguy Nov 27 '16 at 05:28
  • Probably some kind of corrupted file somewhere. Thanks for the quick accept! – GhostCat Nov 27 '16 at 06:37