New to JavaProgramming Center
Java Platform Overview |
Getting Started |
Learning Paths
![]()
Contents Troubleshooting GuideThis page describes the most common problems for compiling and running packaged applications, and the solutions to these problems. Problems Compiling
Problem 1: Compiling Only the
Because the Dive Log consists of multiple files, it is packaged using the
DiveLog.java:60: cannot resolve symbol
symbol : class Welcome
location: class divelog.DiveLog
new Welcome(),
^
DiveLog.java:66: cannot resolve symbol
symbol : class Diver
location: class divelog.DiveLog
new Diver(),
^
DiveLog.java:71: cannot resolve symbol
symbol : class Dives
location: class divelog.DiveLog
new Dives(),
^
DiveLog.java:76: cannot resolve symbol
symbol : class Statistics
location: class divelog.DiveLog
new Statistics(),
^
DiveLog.java:81: cannot resolve symbol
symbol : class WebSite
location: class divelog.DiveLog
new WebSite(),
^
DiveLog.java:85: cannot resolve symbol
symbol : class Resources
location: class divelog.DiveLog
new Resources(),
^
6 errors
Solution to Problem 1 To compile a packaged application you must include the classpath which points to, but does not include, the directory where the files live. If your Dive Log files are in the following directory: C:\Applications\divelog
Step 1: javac -classpath C:\Applications\ DiveLog.java
Note the space after
Problem 2: Leaving off the
If you leave off the invalid argument: divelog.DiveLog
Solution to Problem 2
Misplaced curly braces are the most common cause of compilation errors. It is
easy to lose track of which braces go with certain blocks of code, especially
nested blocks that contain Leaving out or having an extra curly brace in your code can lead to a variety of compilation errors that give little indication of the real problem. At other times, the compiler may highlight a brace, saying you need to include another. Solution to Problem 3
Comment braces as you create them. Mark the opening brace with a comment, such as
The Dive Log application calls all its methods from with the constructor or
from within the
Defining and calling methods can be tricky, so to simplify, only
the
Step 1: Check the curly braces to be certain there aren't extra or missing
braces.
Problems Running the ApplicationRunning the Dive Log application is similar to compiling, but troubleshooting can be more difficult. If your classes compile without error, but the application does not run correctly, determining the problem can be frustrating and difficult. Below are some of the more common problems. Problem 1: Trying to Run Only
If you run the Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog/java You probably tried to run the application with: java DiveLog For a single class application that command normally works. For a multi-class, packaged application it does not. Solution to Problem 1 The rules for compiling the Dive Log apply to running it as well. To run a packaged application you must include the classpath which points to, but does not include, the directory where the classes live. Do not include the package name with the dot, though. If your Dive Log files are in the following directory: C:\Applications\divelog
Step 1: java -classpath C:\Applications\ divelog.DiveLog Note the command to run is slightly different from the compile command:
Problem 2: Naming the Directory Incorrectly Similar to problem 1, the application needs to know where the class files are to be found. If you leave off the directory name in front of the file name, such as: java -classpath C:\Applications\ DiveLog.java you get an error similar to: Exception in thread "main" java.lang.NoClassDefFoundError: DiveLog/java
You also get this error if you include the directory where the class files
live in the classpath. Remember, you must java -classpath C:\Applications\ divelog.DiveLog If you still have problems compiling or running the Dive Log application after reading this page, use the Reader Feedback form. Include the command you used, and the error it generated. Problems and solutions will be added to this page to help all readers. |
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||