简体   繁体   中英

Why do I keep getting java.lang.NoClassDefFoundError at main when I try to run scalafx code in eclipse?

Please I need help with this very simple example here. I can't get to run this without getting this annoying error messages

Exception in thread "main" java.lang.NoClassDefFoundError:
scalafx/application/JFXApp$class
    at HelloScalaFX$.<init>(HelloScalaFX.scala:6)
    at HelloScalaFX$.<clinit>(HelloScalaFX.scala)
    at HelloScalaFX.main(HelloScalaFX.scala)
Caused by: java.lang.ClassNotFoundException: scalafx.application.JFXApp$class
    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)
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.control.Label

object HelloScalaFX extends JFXApp {
    stage = new PrimaryStage {
        scene = new Scene {
            content = new Label {
                text = "Hello ScalaFX"
            }
        }
    }
 }

So, from experience, I can honestly say that if you press the run button on eclipse you should get a popup window that will often ask for a class to run. If not try and right click on your eclipse editor (where you wrote your code) go to run, check the options and select run configurations. At that point you will see what your main class is and what file you want to run. The main class usually starts with the name of the package the file is in ... it might be default if you did not name it and followed by dot name of the class like this your case it would be HelloScalaFx... if you do not see it written then you can type it in manually. . If this also fails... make sure your code contains the package name! after setting those configurations you should be able to run the program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM