getting an odd error with a special class in Java (need help quick!!!)

Status
Not open for further replies.

superspork

Ars Tribunus Militum
1,691
I'm working on a project for my java programming class and I've almost got it finished but whenever i try to run the program after compiling I get this error:


Enter the purchase amount [0.01...20.00] : Exception in thread "main" java.lang.
NoClassDefFoundError: cs1/Keyboard
at project2.main(project2.java:29)

The cs1 mentined is a .jar file and Keyboard is a special clas create for the textbook I'm using. I'm trying to figure it out but its Friday evening and my professor has gone home by now and this project is due in by midnight tonight.

The project (in case you need to know) is to write a program that calculates the change you would get back from a $20 bill and sorts it by denomination. I'll post the code for the project if that is needed as well. I just want to know what this error is and how to fix it.

[This message was edited by superspork on February 22, 2002 at 18:10.]
 

superspork

Ars Tribunus Militum
1,691
would it help if I posted my project code?

Here it goes:

import cs1.Keyboard;
import java.text.NumberFormat;

public class project2
{
//-----------------------------------------------------------------
// TO DO: Calculates
// entered by the user.
//-----------------------------------------------------------------
public static void main (String[] args)
{
double Purchase;

System.out.print (" Enter the purchase amount [0.01...20.00] : ");
Purchase = Keyboard.readDouble();

//Empty line
System.out.println ();

double change;

change = 20.0 - Purchase;

// Print output with appropriate formatting
NumberFormat money = NumberFormat.getCurrencyInstance();

int cents = (int) (100.0 * change + 0.1);

int Denominations;

Denominations = cents / 1000;
System.out.println (" " + Denominations + "Ten Dollar bills");
cents = cents % 1000;

Denominations= cents / 500;
System.out.println (" " + Denominations + " Five Dollar bills");
cents = cents % 500;

Denominations = cents / 100;
System.out.println (" " + Denominations + "One Dollar bills");
cents = cents % 100;

Denominations = cents / 25;
System.out.println (" " + Denominations + "Quarters");
cents = cents % 25;

Denominations = cents / 10;
System.out.println (" " + Denominations + "Dimes");
cents = cents % 10;

Denominations = cents / 5;
System.out.println (" " + Denominations + "Nickles");
cents = cents % 5;

Denominations = cents / 1;
System.out.println (" " + Denominations + "Pennies");
cents = cents % 1;
}
} // class project2
 
The error is telling you that the compiler can't find the class cs1.Keyboard. Two things to verify.

1. The class name really is cs1.Keyboard and not just Keyboard. Just because it is in a jar file called cs1.jar does not mean the class is named cs1.Keyboard

2. Make sure the jar file is part of your class path. When you run the compiler from the directory containing project2.java do the following:

javac -classpath .;cs1.jar project2.java

This assumes that cs1.jar is also in the same directory.

gen
 

superspork

Ars Tribunus Militum
1,691
It's not important anymore. I had to submit it before midnight which was an hour ago. I tried everything that was suggested on #programming on ArsIRC and nothing worked. I put the.jar file in the directory it was supposed to be in and set a path in my autoexec.bat file to my jdk directory. Both things were done accoring to my professor's instructions. Basically I don't know whats wrong but it should be working.

I just had to send it off and plan to explain to my prof what went wrong. I think he'll be understanding about it. There's always the possibility it wa done right the first time anyway.
:)

I can at least hope so anyway.
 
Status
Not open for further replies.