- 浏览: 21974 次
- 性别:
- 来自: 苏州
文章分类
最新评论
Common Problems (and Their Solutions)
- 博客分类:
- java
Compiler Problems
Common Error Messages on Microsoft Windows Systems
'javac' is not recognized as an internal or external command, operable program or batch file
If you receive this error, Windows cannot find the compiler (javac).
Here's one way to tell Windows where to find javac. Suppose you installed the JDK in C:\jdk1.7.0. At the prompt you would type the following command and press Enter:
C:\jdk1.7.0\bin\javac HelloWorldApp.java
If you choose this option, you'll have to precede your javac and java commands with C:\jdk1.7.0\bin\ each time you compile or run a program. To avoid this extra typing, consult the section Updating the PATH variable in the JDK 7 installation instructions.
Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested
If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.
Common Error Messages on UNIX Systems
javac: Command not found
If you receive this error, UNIX cannot find the compiler, javac.
Here's one way to tell UNIX where to find javac. Suppose you installed the JDK in /usr/local/jdk1.7.0. At the prompt you would type the following command and press Return:
/usr/local/jdk1.7.0/javac HelloWorldApp.java
Note: If you choose this option, each time you compile or run a program, you'll have to precede your javac and java commands with /usr/local/jdk1.7.0/. To avoid this extra typing, you could add this information to your PATH variable. The steps for doing so will vary depending on which shell you are currently running.
Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested
If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.
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 processes count++, 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 .class file. Carefully verify the program, fix any errors that you detect, and try again.
Semantic Errors
In 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 errors
Again, your program did not successfully compile, and the compiler did not create a .class file. Fix the error and try again.
Runtime Problems
Error Messages on Microsoft Windows Systems
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.
One of the places java tries to find your .class file is your current directory. So if your .class file is in C:\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 to C:\java>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
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 enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the Updating the PATH variable section in the JDK 7 installation instructions. The CLASSPATH variable is set in the same manner.
Could not find or load main class HelloWorldApp.class
A common mistake made by beginner programmers is to try and run the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java 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 a main method at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses the main method in detail.
Error Messages on UNIX Systems
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.
One of the places java tries 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:
cd /home/jdoe/java
If you enter pwd at the prompt, you should see /home/jdoe/java. If you enter ls at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
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.
unset CLASSPATH
Now enter java HelloWorldApp again. 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 the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java 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 a main method at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses the main method in detail.
源网址:http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html
Common Error Messages on Microsoft Windows Systems
'javac' is not recognized as an internal or external command, operable program or batch file
If you receive this error, Windows cannot find the compiler (javac).
Here's one way to tell Windows where to find javac. Suppose you installed the JDK in C:\jdk1.7.0. At the prompt you would type the following command and press Enter:
C:\jdk1.7.0\bin\javac HelloWorldApp.java
If you choose this option, you'll have to precede your javac and java commands with C:\jdk1.7.0\bin\ each time you compile or run a program. To avoid this extra typing, consult the section Updating the PATH variable in the JDK 7 installation instructions.
Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested
If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.
Common Error Messages on UNIX Systems
javac: Command not found
If you receive this error, UNIX cannot find the compiler, javac.
Here's one way to tell UNIX where to find javac. Suppose you installed the JDK in /usr/local/jdk1.7.0. At the prompt you would type the following command and press Return:
/usr/local/jdk1.7.0/javac HelloWorldApp.java
Note: If you choose this option, each time you compile or run a program, you'll have to precede your javac and java commands with /usr/local/jdk1.7.0/. To avoid this extra typing, you could add this information to your PATH variable. The steps for doing so will vary depending on which shell you are currently running.
Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested
If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.
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 processes count++, 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 .class file. Carefully verify the program, fix any errors that you detect, and try again.
Semantic Errors
In 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 errors
Again, your program did not successfully compile, and the compiler did not create a .class file. Fix the error and try again.
Runtime Problems
Error Messages on Microsoft Windows Systems
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.
One of the places java tries to find your .class file is your current directory. So if your .class file is in C:\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 to C:\java>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
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 enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the Updating the PATH variable section in the JDK 7 installation instructions. The CLASSPATH variable is set in the same manner.
Could not find or load main class HelloWorldApp.class
A common mistake made by beginner programmers is to try and run the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java 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 a main method at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses the main method in detail.
Error Messages on UNIX Systems
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.
One of the places java tries 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:
cd /home/jdoe/java
If you enter pwd at the prompt, you should see /home/jdoe/java. If you enter ls at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
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.
unset CLASSPATH
Now enter java HelloWorldApp again. 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 the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java 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 a main method at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses the main method in detail.
源网址:http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html
发表评论
-
中文与Unicode转换
2013-08-21 09:31 521package unicode; import java.ut ... -
The type java.lang.Object cannot be resolved. It is indirectly referenced from r
2013-05-27 16:32 1244The type java.lang.Object canno ... -
Linux系统中的tomcat定时重启脚本(转)
2013-05-24 15:00 9471.Linux下tomcat重启脚本 [root@]# vi ... -
no acceptable C compiler found in $PATH问题解决办法
2013-03-25 14:18 2960自已安装 yum install gcc yum in ... -
好的网站
2013-03-08 13:34 519jQuery MiniUI Demo http://www.m ... -
myeclipse+tomcat中出现org.apache.juli.logging.LogFactory
2013-02-21 15:41 701[转]将项目部署好后,启动tomcat后报错,java.lan ... -
MySQL 5.6 正式版发布
2013-02-19 11:45 671近日,Oracle发布了MySQL 5.6分支的首个正式版本— ... -
Imagemagick + jmagick配置
2013-02-18 10:09 773magemagick + jmagick 版本:ImageMa ... -
MyEclipse中如何设置 jdk 和 jre 编译运行环境 (转)
2013-02-18 10:07 1106MyEclipse设置JDK和JRE具体的应用版本其实很简单, ... -
Apache Struts 2 Documentation
2013-02-01 15:56 586http://struts.apache.org/2.3.1. ...
相关推荐
This book will help the technician, engineer and user understand the microcontroller-based systems along with the most common problems and their solutions. This book covers design, specification, ...
These describe common problems and their solutions. The section describes the design principles that make patterns powerful. It covers many of the classic design patterns and includes chapters on ...
Focusing on BeautifulSoup4 and Scrapy, this concise, focused book highlights common problems and suggests solutions that readers can implement on their own. Website Scraping with Python starts by ...
Focusing on BeautifulSoup4 and Scrapy, this concise, focused book highlights common problems and suggests solutions that readers can implement on their own. Website Scraping with Python starts by ...
I don't mean to say that it touches on every detail of C++ that would require many more pages he C++ language and library features to show how apparently unrelated items can be used together to ...
App Development Recipes for iOS and watchOS: A Problem-Solution Approach ...Who this book is for:Developers who need to find specific solutions to common problems in developing apps for iOS and watchOS.
DBAs looking for solutions to common problems encountered during their day-to-day tasks while working with Redis will also find this book useful. The book covers all the aspects of using Redis and ...
HTML5 Solutions provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.
We discover and summarize the most common problems and derive the solutions; not just a short answer and screenshot, but a systematic, logical derivation, that is, how we got to the solution. After ...
you'll find specific solutions around storing login credentials, local data caching, and sending authorization tokens in HTTP requests. Not only do the solutions in the book solve specific problems,...
you'll quickly get down to the nitty-gritty with chapters on choosing a phone service, planning for VoIP, installing the equipment, setting up service, common VoIP problems (and their solutions!...
The latest VDI release has brought with it various enhancements that will provide a better way to solve the common problems that occur while designing a VDI solution. This book will guide you ...
Covers common research problems in medical image analysis and their challenges Describes deep learning methods and the theories behind approaches for medical image analysis Teaches how algorithms are ...
Whether you’re deploying applications on-premise or in the cloud, this cookbook is for developers, operators, and IT professionals who need practical solutions for using Docker. The recipes in this ...
Design patterns in the book help to solve common problems encountered when developing data integration solutions. The patterns and solution examples in the book increase your efficiency as an SSIS ...
Carlos Oliveira, "Options and ... Readers will be able to directly apply the concepts and sample code to some of the most common problems faced in the analysis of options and derivative contracts.
Ancillary materials include problems and solutions, programming exercises, simulation experiments, and a wide range of fully working sample applications with complete source code developed in C++, C# ...
step through various implementations of genetic algorithms and some of their common applications, with the aim to give you a practical understanding allowing you to solve your own unique, individual ...
2.3 Continuous Linear Systems and their Solutions, 47 2.4 Discrete Linear Systems and their Solutions, 59 2.5 Observability of Linear Dynamic System Models, 61 2.6 Summary, 66 Problems, 69 References,...