jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Problems with Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problems with Packages" Watch "Problems with Packages" New topic

Problems with Packages

Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
I have some sample code that uses a package statement.
If I compile the code with the package statement it creates a *.class file, however, the java.exe command returns a�
"Exception in thread "main" java.lang.NoClassDefFoundError: ListRecords"
If I comment out the package statement the class runs fine.
The original package statement is package jt400;
The class is named ListRecords and is a record level access program to read data from a DB2 file.
The class path is correct, because the package is required for compilation and the necessary classes are accessed. I verified this with a �-verbose� compile.
Any ideas? I've tried specifying the path to the package explicitly in the package statement. The results were the same.
Am I not supposed to call the class in the usual manner?
Obviously, I have not used packages yet. Any help would be appreciated,

Anxiety does not empty tomorrow of its sorrows, but only empties today of its strength. – Charles Spurgeon
marilyn murphy
Ranch Hand

Joined: Aug 28, 2001
Posts: 84
Is ListRecords the class containing main()? Which subdirectory is ListRecords.class in?
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
This thread may help you.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
Originally posted by marilyn murphy:
Is ListRecords the class containing main()? Which subdirectory is ListRecords.class in?

Yes, it is. In fact if I remove the package statement, and re-compile, the class will run fine.
The ListRecords.class is in the same directory as the package.
I'll try the import statement that was suggested in the other thread mentioned and if I still have trouble, today, I'll add the pertinant part of the code to this thread.

[This message has been edited by Ray Marsh (edited September 24, 2001).]
Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
Still having a problem
Here's the specifics...
This is the output from the compile

> cd C:\JCode\Source
> C:\jdk1.2.2\bin\javac.exe -verbose ListRecords.java
C:\JCode\Source>C:\jdk1.2.2\bin\javac.exe -verbose ListRecords.java
[parsed ListRecords.java in 710 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/Object.class) in 0 ms]
[checking class jt400.ListRecords]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/AS400.class) in 60 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/Throwable.class) in 50 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/io/Serializable.class) in 0 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/QSYSObjectPathName.class) in 60 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/SequentialFile.class) in 60 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/AS400File.class) in 50 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/AS400Exception.class) in 0 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/ErrorCompletingRequestException.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/Exception.class) in 0 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/ReturnCodeException.class) in 0 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/AS400SecurityException.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/InterruptedException.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/io/IOException.class) in 0 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/AS400FileRecordDescription.class) in 50 ms]
[loaded C:\jdk1.1.7b\lib\jt400.jar(com/ibm/as400/access/Record.class) in 60 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/math/BigDecimal.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/Number.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/Comparable.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/String.class) in 50 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/System.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/io/PrintStream.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/io/FilterOutputStream.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/io/OutputStream.class) in 60 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/Error.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/RuntimeException.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/beans/PropertyVetoException.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/io/UnsupportedEncodingException.class) in 0 ms]
[loaded C:\JDK1.2.2\JRE\lib\rt.jar(java/lang/StringBuffer.class) in 0 ms]
[wrote ListRecords.class]
[done in 2030 ms]

Here's what I get when I try to run it
> cd C:\JCode\Source
> C:\jdk1.2.2\bin\java.exe ListRecords
C:\JCode\Source>C:\jdk1.2.2\bin\java.exe ListRecords
java.lang.NoClassDefFoundError: ListRecords (wrong name: jt400/ListRecords)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:442)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:101)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
at java.lang.ClassLoader.loadClass(ClassLoader.java:290)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main"

Here's the first part of the code...
package jt400;
import jt400.*;
import java.io.*;
import java.util.*;
import java.math.*;
import com.ibm.as400.access.*;
public class ListRecords {
public ListRecords() {
// Step 1:
// Connect to an AS/400
AS400 system = new AS400(); ....

Any help is much appreciated. Thank you.
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
Use "java jt400.ListRecords". It should work.
Since the class ListRecords is in a package "jt400", It should be called using jt400.ListRecords(<packagename.classname>).

Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569

Use "java jt400.ListRecords"
The class is referred using jt400.ListRecords(<packagename.Classname>), since ListRecords is in the package jt400
Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
Ok, thanks everyone for your help.
It finally worked. Here's what I did wrong, in case someone else makes the same mistakes I did.
1) Did not have all lower case letters in the package statement.
2) Did not have the directories for the package in the classpath.
3) Assumed that the compiler would place the class in the package automatically. I thought that's what I read, but it did not work that way. However, when I manually moved the class to the package folder, it worked fine, with the other two problems corrected.
Thanks again.
I agree. Here's the link: http://aspose.com/file-tools
subject: Problems with Packages
It's not a secret anymore!