Re: GUI example won't work
wow, is is that hard to make package 'components', compile the project with single file and run it via its main method
it works
http://img15.imageshack.us/img15/2164/textdemo.jpg
Re: GUI example won't work
Quote:
Originally Posted by
coder752
Why won't it run?
It works fine here.
Dude - we're not mind readers - if you want help with something, give us information - how are you trying to run it? what happens when you try to run it? What did you expect to happen? Do you get an error message? If so, post up the full text of the error message.
Judge a man by his questions, rather than his answers...
Voltaire
Re: GUI example won't work
Error message reads like this:
Exception in thread "main" java.lang.NoClassDefFoundError: TextDemo (wrong name:
components/TextDemo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: TextDemo. Program will exit.
Re: GUI example won't work
Quote:
Originally Posted by
coder752
Error message reads like this:
Exception in thread "main" java.lang.NoClassDefFoundError: TextDemo (wrong name:
components/TextDemo)
...
Could not find the main class: TextDemo. Program will exit.
OK, you didn't answer my question about how you ran it, which isn't very helpful, but I'll take a guess anyway...
The TextDemo class is in package directory 'components', so its fully qualified name is 'components.TextDemo', but I'm guessing you told it to run just 'TextDemo' instead, from inside the 'components' directory. The runtime read the TextDemo class, saw the 'components' package declaration and realised the name was wrong. When you run classes, you should run them from the directory that contains the root package directory, and specify the fully qualified name (i.e. include the package or packages in the name).
This is very basic stuff - I recommend you learn about packages and how to run a Java program with java.exe.
Unless in communicating with it [a computer] one says exactly what one means, trouble is bound to result...
A. Turing
Re: GUI example won't work
Ok, so I transferred my code to a new directory called components. I placed TextDemo.java in there. I added this line of code in the heading as well
Code:
import components.*;
Next...
I did a javac TextDemo.java (compiles)
Then I did java components.TextDemo
I ran it, but again, it gave me the same error.
I read the Java Sun Tutorial, helpful in other ways, just not this one.
Re: GUI example won't work
Quote:
Originally Posted by
coder752
I added this line of code in the heading as well
Code:
import components.*;
Why? There are no other classes involved - the comments in the code itself say no other files are required.
Quote:
I did a javac TextDemo.java (compiles)
Then I did java components.TextDemo
I ran it, but again, it gave me the same error.
You probably missed the bit in my previous post where I said:
Quote:
When you run classes, you should run them from the directory that contains the root package directory
This will be the directory where you put 'components'. The Java runtime expects to be pointed to the directory that contains the packages (this directory is often called 'classes'). You can do this either by being in that directory when you run it, or by putting that directory on the classpath so Java knows where to look for the packages. Setting the classpath is probably the next thing you'll learn, so for now just run it from the directory that contains the 'components' directory. So when you run it, it should see the directory 'components' that matches the package name in the Java command, and inside that it will find TextDemo.class, which matches the class name in the Java command.
If you understand what you're doing, you're not learning anything...
Anon.