Developer Forums relocated!

Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

CS1 for Java (Keyboard Input)

For my Computer Science class, we have to download and use the Keyboard Class. So I downloaded the cs1.jar file and Keyboard.java (from which I compiled the Keyboard.class file) and put all three things in the folder which I save my Java files to. I then opened DrJava and tried to compile the program the teachers told us to use to test it:
// File: InputTest.java
import cs1.Keyboard;

public class InputTest {
public static void main(String[] args) {
int i;
System.out.print("Type a number, followed by the Enter key: ");
i = Keyboard.readInt();
System.out.println("The number is: " + i);
}
}

It didn't work. I then opened the Keyboard.java file in DrJava, so both were open at the same time. Then, I was able to compile InputTest.java without a problem. But when I tried to run it, it gave me this error message: NoClassDefFoundError: cs1/Keyboard
at InputTest.main(InputTest.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:25)
at java.lang.reflect.Method.invoke(Method.java:585)


I'm tearing my hair out trying to get this to work. Please help!

iMac G4 17", Mac OS X (10.4.7)

Posted on Oct 2, 2006 8:58 AM

Reply
Question marked as Best reply

Posted on Oct 2, 2006 9:30 AM

Hi Max

It's not your fault but I am appalled that Java teachers are still using bodges like the Keyboard class, when the standard Scanner class has been available for over 12 months.

So here's what I suggest:

1) Try putting the jar file into /Library/Java/Extensions

2) Tell your tutor to get his notes up to date and use the Scanner class instead of Keyboard 😉

Bob
3 replies
Question marked as Best reply

Oct 2, 2006 9:30 AM in response to mlivingston

Hi Max

It's not your fault but I am appalled that Java teachers are still using bodges like the Keyboard class, when the standard Scanner class has been available for over 12 months.

So here's what I suggest:

1) Try putting the jar file into /Library/Java/Extensions

2) Tell your tutor to get his notes up to date and use the Scanner class instead of Keyboard 😉

Bob

CS1 for Java (Keyboard Input)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.