views:

270

answers:

2

I successfully implemented and ran several Scala tutorials in Eclipse using the Scala plugin. Then suddenly I tried to compile and run an example, and this error came up:

Exception in thread "main" java.lang.NoClassDefFoundError: hello/HelloWorld
Caused by: java.lang.ClassNotFoundException: hello.HelloWorld
 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

After this point I could no longer run any Scala programs in Eclipse. I tried cleaning and rebuilding my project, closing and reopening my project, and closing and reopening Eclipse.

Eclipse version number 3.5.2 and Scala plugin 2.8.0

Here is the original code:

package hello

object HelloWorld {
 def main(args: Array[String]){
  println("hello world")
 }
}
+3  A: 

If you see this when you attempt to run as a Scala application then the most likely explanation is that your project didn't compile and no class files were generated. Please check whether or not that's the case: look in your project's output folder for hello/HelloWorld.class.

If your project didn't compile that could either be because there's an error which you've missed (and if this error isn't being reported in the Problems view that could be a bug, in which case please open a ticket on Trac) or because you've turned off automatic builds and not done a manual build of your project.

Miles Sabin
There were no files in the output folder. Unfortunately I reinstalled my environment yesterday to get everything working so I can't further troubleshoot.
Jacob Lyles
+1  A: 

When running "clean" does not un-hose Eclipse, I next try saving my work, exiting Eclipse, and re-starting. That usually gets things going again, but not always. A few times I've had to update the Scala plugin with a more recent version (I'm using the latest nightly), to get things working again. I doubt that this worked because the new plugin happened to fix the bug, but rather expect that loading the new plugin gives the whole Eclipse-Scala system a "total reset" that gets it unhosed.

Terry Woodrff