《JAVA代码编写的常见错误1.pdf》由会员分享,可在线阅读,更多相关《JAVA代码编写的常见错误1.pdf(2页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、常见错误常见错误 1 1JavaJava 介绍介绍问题一问题一:WhenWhen youyou compilecompile youryour program,program,youyou receivereceive anan errorerror asas follows:follows:%javac Welcome.javajavac not foundWhat is wrong?答案:Two possible reasons:1.Java is not installed on your system;or 2.Java is installed,butthe environment
2、variable PATH is not set.问题二问题二:WhenWhen youyou compilecompile youryour program,program,youyou receivereceive anan errorerror asas follows:follows:%javac Welcome.javajavac:file not found:Welcome.javaUsage:javacuse-help for a list of possible optionsWhat is wrong?答案:File Welcome.java does not exist i
3、n the directory.Check ifWelcome.java is in the current directory.问题三问题三:When you run your program,you receive an error as follows:When you run your program,you receive an error as follows:%java WelcomeException in thread main java.lang.NoClassDefFoundError:WelcomeWhat is wrong?答案:File Welcome.class
4、does not exist.You have to first compileWelcome.java to produce Welcome.class in the current directory.问题四问题四:When you run your program,you receive an error as follows:When you run your program,you receive an error as follows:%java WelcomeException in thread main java.lang.NoSuchMethodError:mainWhat
5、 is wrong?答案:Please check if you have a main method in Welcome.java or youhave spelled the method public static void main(String args)correctly.问题五问题五:WhenWhen youyou compilecompile youryour program,program,youyou receivereceive anan errorerror asas follows:follows:%javac Welcome.javaWelcome.java:2:cannot find symbolsymbol :class stringlocation:class Welcome public static void main(string args)1 errorWhat is wrong?答案:Java is case-sensitive.string should be spelled as String.
限制150内