It Didn't Work!
Okay, so since these are computers we are dealing with, it is possible that you had some trouble compiling and executing your test case.
Here are a few possible solutions.
| Error | Solution |
| "Bad command or filename" |
Did you spell everything right?
If so, you probably have not set your PATH environment variable correctly and the computer cannot find the javac or java virtual machine executable.
Either set your path correctly, or reference the executable exactly with something like:
C:\Java\Sun\jdk1.1.4\Bin\javac Test.java
|
| Error | Solution |
| "ClassDefNotFound Error" |
You have not defined your CLASSPATH correctly and the java compiler cannot find the java class library it needs.
| | "Public class Test must be defined in a file called 'Test.java'" |
You have to be careful about case-sensitivity when programming in Java.
You probably typed "javac test.java."
Try typing the javac command again with a capital "T"
| | "Can't find class Test/class" |
You were probably trying to execute your compiled test class and typed java Test.class.
You should not use the .class extension.
Try typing
java Test
| | "Can't find class test" |
Case sensitivity again!
You probably typed "java test" and it should be "java Test"
| | "Test.java:7: ';' expected". |
You forgot to end that line with a semi-colon
| | "Return required at end of java.lang.String getAnnouncement()" |
You forgot to say
return _announcement;
at the end of this method.
Remember that if you say you are going to return something, you have to do it.
| | "Announcer.java:22: Undefined variable: _announcement" |
In this case, _announcement is spelled wrong.
However, it could also mean that you have defined the _announcement variable in a method that is not accessible.
Remember that if you want variables to be available to other methods in the same class, you must declare them outside of the method.
|
NEXT
Selena Sol contributes to the JavaBoutique's Introduction to Java. Selena curently works for Barclays Capital in London, one of the leading global investment banks in Europe and has worked as a software developer for the National Center for Human Genome research, Microline Software, Neuron Data, and Electric Eye in Singapore. Selena is perhaps best-known for creating the Public Domain Web Script Archive (Extropia) and writing several books on Web Programming (Perl, CGI, Java).
Email: selena@extropia.com
|