In Part 1 of this series i have explained about the basic class structure, here i will let you know about the common problems that you can face while compiling and running your first java program.
When you attempt to compile your first program and you use javac command from your command prompt, then you can see following message:
When you attempt to compile your first program and you use javac command from your command prompt, then you can see following message:
- prob:
'javac' is not recognized as an internal or external command, operable program or batch file.
Solution :If you receive this error, Windows cannot find the compiler (javac).Here's one way to tell Windows where to findjavac. Suppose you installed the JDK inC:\jdk1.7.0. At the prompt you would type the following command and press Enter:C:\jdk1.7.0\bin\javac Abc.java If you choose this option, you'll have to precede yourjavacandjavacommands withC:\jdk1.7.0\bin\each time you compile or run a program. To avoid this extra typing,follow my post here.Prob :Class names, 'Abc', are only accepted if annotation processing is explicitly requested.Solution : If you receive this error, you forgot to include the.javasuffix when compiling the program. Remember, the command isjavac Abc.javanotjavac Abc.
- Prob : 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.
- Solution : Follow the error message generated by compiler and check your code for syntax.
- Prob: java.lang.NoSuchMethodError : main Exception in thread "main".
- Solution: to run our compiled java program our class need to have main method having signature as public static void main(String[] args){ }
- Prob :
Exception in thread "main" java.lang.NoClassDefFoundError: Abc Solution :If you receive this error,javacannot find your bytecode file,Abc.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:\java
The prompt should change toC:\java>. If you enter dirat the prompt, you should see your.javaand.classfiles. Now enterjava Abcagain.
If you still have problems, you might have to change your CLASSPATH variable. To see if this is necessary, try to set the classpath with the following command.
Now enterset CLASSPATH=java Abcagain. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, click here. The CLASSPATH variable is set in the same manner.
-
Prob
: could not find and load main class in Abc.class Solution :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 Abc.classinstead ofjava Abc. Remember, the argument is the name of the class that you want to use, not the filename.
No comments:
Post a Comment