1ST WE WILL DISCUSS ABOUT COMMON ERROR'S FOR JAVA ON DIFFERENT PLATFORM'S.
Common Error Messages on UNIX Systems
javac: Command not found
THIS MEANS YOUR OS HAS NOT THE COMPILER JAVAC HENCE HE DOES NOT FIND IT.
TO SOLVE THIS ERROR 1ST YOU HAVE TO INSTALL COMPILER FIRST...
FOLLOW THE STEPS:
DOWNLOAD .ZIP FILE OF JAVA JDK FROM NET AND PASTE HERE IN DIR.
Syntax Errors (All Platforms)
Common Error Messages on UNIX Systems
javac: Command not found
THIS MEANS YOUR OS HAS NOT THE COMPILER JAVAC HENCE HE DOES NOT FIND IT.
TO SOLVE THIS ERROR 1ST YOU HAVE TO INSTALL COMPILER FIRST...
FOLLOW THE STEPS:
DOWNLOAD .ZIP FILE OF JAVA JDK FROM NET AND PASTE HERE IN DIR.
Here's one way to tell UNIX where to find
javac. Suppose you installed the JDK in /usr/local/jdk1.7.0.
Common Error Messages on Microsoft Windows Systems:
similarly if you don't install jdk and type in cmd>javac then it will display error.
to solve this error 1st you have to install jdk from oracle website or from sun microsystem website.
To access the compiler in any folder you have to set one path.
1.right click on my computer .
2.click on properties.
3.select advanced system setting.
4.select environmental variables.
5. click on new
add path
variable name=path
variable path=.;C:\Program Files\Java\jdk1.6.0_27\bin
add the classpath
here is variable name:classpath
variable path=.;C:\Program Files\Java\jdk1.6.0_27\jre\lib\rt.jar
Syntax Errors (All Platforms)
If you mistype part of a program, the compiler may issue a syntax error. The message usually displays the type of the error, the line number where the error was detected, the code on that line, and the position of the error within the code. Here's an error caused by omitting a semicolon (
;) at the end of a statement:testing.java:14: `;' expected.
System.out.println("Input has " + count + " chars.")
^
1 error
Sometimes the compiler can't guess your intent and prints a confusing error message or multiple error messages if the error cascades over several lines. For example, the following code snippet omits a semicolon (
;) from the bold line:while (System.in.read() != -1)
count++
System.out.println("Input has " + count + " chars.");
When processing this code, the compiler issues two error messages:
testing.java:13: Invalid type expression.
count++
^
testing.java:14: Invalid declaration.
System.out.println("Input has " + count + " chars.");
^
2 errors
The compiler issues two error messages because after it processescount++, the compiler's state indicates that it's in the middle of an expression. Without the semicolon, the compiler has no way of knowing that the statement is complete.If you see any compiler errors, then your program did not successfully compile, and the compiler did not create a.classfile. Carefully verify the program, fix any errors that you detect, and try again.Semantic ErrorsIn addition to verifying that your program is syntactically correct, the compiler checks for other basic correctness. For example, the compiler warns you each time you use a variable that has not been initialized:testing.java:13: Variable count may not have been initialized. count++ ^ testing.java:14: Variable count may not have been initialized. System.out.println("Input has " + count + " chars."); ^ 2 errorsAgain, your program did not successfully compile, and the compiler did not create a.classfile. Fix the error and try again.
Runtime Problems
Error Messages on Microsoft Windows SystemsException in thread "main" java.lang.NoClassDefFoundError: HelloWorldAppIf you receive this error,javacannot find your bytecode file,HelloWorldApp.class.One of the placesjavatries to find your.classfile is your current directory. So if your.classfile is inC:\java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Enter:cd c:\javaThe prompt should change toC:\java>. If you enterdirat the prompt, you should see your.javaand.classfiles. Now enterjava HelloWorldAppagain.If you still have problems, you might have to change your CLASSPATH variable. To see if this is necessary, try clobbering the classpath with the following command.set CLASSPATH=Now enterjava HelloWorldAppagain. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the Updatiag the PATH variable section in the JDK 7 installation instructions. The CLASSPATH variable is set in the same manner.Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/classA common mistake made by beginner programmers is to try and run thejavalauncher on the.classfile that was created by the compiler. For example, you'll get this error if you try to run your program withjava HelloWorldApp.classinstead ofjava HelloWorldApp. Remember, the argument is the name of the class that you want to use, not the filename.Exception in thread "main" java.lang.NoSuchMethodError: mainThe Java VM requires that the class you execute with it have amainmethod at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses themainmethod in detail.Error Messages on UNIX SystemsIf you receive this error,Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldAppjavacannot find your bytecode file,HelloWorldApp.class.
One of the placesjavatries to find your bytecode file is your current directory. So, for example, if your bytecode file is in/home/jdoe/java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Return:
If you entercd /home/jdoe/javapwdat the prompt, you should see/home/jdoe/java. If you enterlsat the prompt, you should see your.javaand.classfiles. Now enterjava HelloWorldAppagain.
If you still have problems, you might have to change your CLASSPATH environment variable. To see if this is necessary, try clobbering the classpath with the following command.
Now enterunset CLASSPATHjava HelloWorldAppagain. If the program works now, you'll have to change your CLASSPATH variable in the same manner as the PATH variable above.
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class
A common mistake made by beginner programmers is to try and run thejavalauncher on the.classfile that was created by the compiler. For example, you'll get this error if you try to run your program withjava HelloWorldApp.classinstead ofjava HelloWorldApp. Remember, the argument is the name of the class that you want to use, not the filename.
Exception in thread "main" java.lang.NoSuchMethodError: main
The Java VM requires that the class you execute with it have amainmethod at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses themainmethod in detail.
No comments:
Post a Comment