This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I try to create my own package and use a class from that package in a program. I used two snippets of code from textbook, which I think the codes themselves are correct. The first code: package com.deitel.jhtp3.ch08; import java.text.DecimalFormat; // used for number formatting // This class maintains the time in 24-hour format public class Time1 extends Object { private int hour; // 0 - 23 private int minute; // 0 - 59 private int second; // 0 – 59 ……………. The second code: import javax.swing.JOptionPane; import com.deitel.jhtp3.ch08.Time1; // import Time1 class public class TimeTest { public static void main( String args[] ) { …………… Step 1: I compile the first by typing “ javac –d c:\jdk1.3.1_01\jre\classes Time1.java ” in command window, everything is going very well , and Time1.class file was placed in c:\jdk1.3.1_01\jre\classes\ com\deitel\jhtp3\ch08. Step2: I compile the second by typing “ javac TimeTest.java ”, it is going well until now. Step3: I run it using “java TimeTest ” , here does occur error message, which I don’t know where I m wrong. E:\9024\test1>java TimeTest Exception in thread "main" java.lang.NoClassDefFoundError: com/deitel/jhtp3/ch08/Time1
hi Before using package try to learn more about classpath. In your case use the following in your command prompt. set classpath=%classpath%;c:\jdk1.3.1_01\jre\classes;.; then run your programm it will work. -arun
Sharing is learning
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
wliu807 Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy. Thanks again and we hope to see you around the ranch!!