• Post Reply Bookmark Topic Watch Topic
  • New Topic

the error in using myself created package

 
wliu807
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

is there anyone who has idea about my errors?

Exception in thread "main" java.lang.NoClassDefFoundError: com/deitel/jhtp3/ch08/Time1
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!