This would seem to be the simplest thing but it is bothering me in two ways.
One is that something isn't working properly.
And two is that I can't seem to figure out how to fix it.
The source file comes from the sun.java website as follows:
This compiles with no complaints but when I try to run it I get this:
charles@linux-hoq0:~/javaJunk/HelloWorld> java HelloWorldSwing Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing (wrong name: start/HelloWorldSwing) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) charles@linux-hoq0:~/javaJunk/HelloWorld>
I've looked all over the place (including these forums) for answers and found many different suggestions. None of the suggestions apply in any way I'm aware of. In my book, Head First Java, swing apps aren't covered until chapter 12 and I'm only on Ch.3 so it's not a panic, but it still bothers me.
I have Java 1.5.0_08 on a 64 bit linux box (Open Suse 10.2)
Any help I could get would be well appreciated.
Cheers<br />Charles<br /> <br />Sometimes we live no particular way but our own.<br />~ Robert Hunter, Grateful Dead
A .class file must exist in a directory structure equal to it's package. So for your example there should be a folder start and the class file should be placed there.
For simplicity sake, remove the package declaration, compile, and try and run it without the start. on the front.
Joined: Sep 28, 2007
Well sheriff, that seems to have done the trick.
That makes me wonder why that line was included in the first place. Probably just to confuse us greenhorns, I reckon. Seems like the author at Sun threw in that line the same way I'd always include the line in C++:
Only this time it referred to something that wasn't there, something the Sun programmer wrote, eh?
No problem. I don't have that particular book but I know the authors. In fact, one of them started this dinky little site many many moons ago and then sold it to Paul Wheaton to run.
Just as an FYI:
The java equivalent to using namespace std; is the import statement, which I am sure you'll get into soon enough. The package delcaration is how a namespace is created. For example, say someone wrote a class you decided to use called MyCoolObject and you decided that was a pretty stinkin cool name and you want to name one of your classes MyCoolObject.
If we didn't have namespaces (packages) then it couldn't be done. However you might place yours in a package called com.charles and you would declare it as such:
Now the conflict is gone. And your .class file would exist in a directory structure:
You'll get it. Just takes time and lots of writing code.