常见错误 1 Java 介绍
问题一 问题一: When you compile your program, you receive an error as follows: %javac Welcome.java javac not found What is wrong? 答案: Two possible reasons: 1. Java is not installed on your system; or 2.
Java is installed, but the environment variable PATH is not set. 问题二 问题二: When you compile your program, you receive an error as follows: %javac Welcome.java javac: file not found: Welcome.java Usage: javac use -help for a list of possible options What is wrong? 答案: File Welcome.java does not exist in the directory. Check if Welcome.java is in the current directory. 问题三
问题三: When you run your program, you receive an error as follows: %java Welcome Exception in thread "main" java.lang.NoClassDefFoundError: Welcome What is wrong? 答案: File Welcome.class does not exist. You have to first compile Welcome.java to produce Welcome.class in the current directory. 问题四 问题四: When you run your program, you receive an error as follows: %java Welcome Exception in thread "main" java.lang.NoSuchMethodError: main
What is wrong? 答案: Please check if you have a main method in Welcome.java or you have spelled the method public static void main(String[] args) correctly. 问题五 问题五: When you compile your program, you receive an error as follows: %javac Welcome.java Welcome.java:2: cannot find symbol symbol : class string location: class Welcome public static void main(string[] args) { ^ 1 error What is wrong? 答案: Java is case-sensitive. string should be spelled as String.