Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Keyboard.class error

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Keyboard.class error

    Hi Guy's
    I'm a first yr computing degree student and have run into a problem at a really bad time
    my JDK is acting up. I'm getting the following error when I try to compile any Java programs (even ones which previously worked)



    \Airline.java:21: cannot access Keyboard
    bad class file: .\Keyboard.class
    class file contains wrong class: cs1.Keyboard
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    option = Keyboard.readChar();
    ^
    1 error

    Tool completed with exit code 1


    I've tried several things from downloading a new Keyboard.class file to re-installing the JDK and Keyboard.class after some googleing I also tried adding the line package cs1; to my program and whilst this had some affect I'm now getting the "Unable to find Variable: Keyboard error"

    Any Assistance would be great. I've a project due for submission on Friday which is worth 50% of my whole Java module and I can't do any coding at home because of this issue

    Here is some of my code so far
    class Airline{//start class
       	public static void main(String[] args){//start main
     
     
    	char option,YesNo='N';//declare char variable
     
    	char seatplan[][] = new char [10][5];
     
     
    	System.out.println("Welcome To Raptor Air Please make a selsection from the options below");//print to screen
     
    	System.out.println("*******************************************");//print to screen
    	System.out.println("Please Enter [A] To View Seat Plan");// ask for user input#
    	System.out.println("Please Enter [B] To Book A Seat ");// ask for user input
    	System.out.println("Please Enter [C] To Cancel A Booking");// ask for user input
    	System.out.println("Please Enter [D] To RESET ALL SEATS");// ask for user input
    	System.out.println("Please Enter [E] To EXIT");// ask for user input
    	System.out.println("*******************************************");//print to screen
     
    	option = Keyboard.readChar();//the value of variable "table" is inputed from keyboard
     
    	option= Character.toUpperCase(option);//switch lowercase entry to uppercase
     
    		switch (option)//switch statement
    		{//start of switch conditions
    		case 'A': System.out.println("Seat Plan");System.out.println("");Plan(seatplan);break;// case A print Seat Plan to screen and call procedure(plan)passing array parameters
    		case 'B': System.out.println("Book A Seat");System.out.println("");  Book(seatplan); break;// case B print Book A Seat to screen and call procedure(Book)passing array parameters
    		case 'C': System.out.println("Cancel A Booking");System.out.println(""); Cancel(seatplan);break;// case C print Cancel A Seat to screen and call procedure(Cancel)passing Array parameters
    		case 'D': System.out.println("Reset All Seats");System.out.println(""); Reset(seatplan);break;// case D print Reset All Seats to screen and call procedure(Reset)passing Array parameters
    		case 'E': Exit();break;// case C print multiply to screen and call procedure(mod)passing parameters
    		default:System.out.println ("This is Not A Valid Entry "); break;// if the Letter. entered is not A,B or C tell the user "This Is Not A Valid Entry"
     
    		}//end off switch
     
     
     
     
     
     
     
     
     
     
     
     
     
    			}//end main
     
     
     
     
     
    			static void Plan(char seatplan[][]) {
    				System.out.println("  A       B       C       D");
    				for(int r=1;r<5;r++){
    								System.out.print("\n");
    								System.out.print( r);
    								System.out.print("");
     
    								for (int c=1;c<seatplan[c].length;c++){
     
    									System.out.print(" -");
     
     
     
     
    					System.out.print("	"+ seatplan[r][c]);
     
     
     
     
    }
     
    }
     
     
    System.out.print("\n");
    System.out.print("\n");System.out.print("\n");
     
     
    for(int r=5;r<9;r++){
    								System.out.print("\n");
    								System.out.print( r);
    								System.out.print("");
     
    for (int c=1;c<seatplan[r].length;c++){
     
    									System.out.print(" -");
     
     
     
     
    					System.out.print("	"+ seatplan[r][c]);
    }
    }
     
    System.out.print("\n");
    System.out.print("\n");System.out.print("\n");
     
    			}
     
     
     
     
     
    			static void Book(char seatplan[][]) {
     
    								System.out.println("  A       B       C       D");
    								for(int r=1;r<5;r++){
     
     
    									System.out.print("\n");
    									System.out.print( r);
    									System.out.print("");
     
    									for (int c=1;c<seatplan[c].length;c++){
     
     
    										System.out.print(" -");
    										System.out.print("	"+ seatplan[r][c]);
     
     
     
     
    				}
     
    				}
     
     
     
     
     
    				System.out.print("\n");
    				System.out.print("\n");System.out.print("\n");
     
     
    				for(int r=5;r<9;r++){
    												System.out.print("\n");
    												System.out.print( r);
    												System.out.print("");
     
    				for (int c=1;c<seatplan[r].length;c++){
     
    													System.out.print(" -");
     
     
     
     
    									System.out.print("	"+ seatplan[r][c]);
    				}
    				}
     
    				System.out.print("\n");
    				System.out.print("\n");System.out.print("\n");
     
     
     
     
     
     
     
    				System.out.println("please Enter the Seat Ref [row num then seat num]");
     
    				char status;
     
    				String ref =new String();
    				ref= Keyboard.readString();
     
     
     
     
    							}
     
     
     
     
     
     
     
     
    			static void Cancel(char seatplan[][]){
    			}
     
    			static void Reset(char seatplan[][]){
     
    		}
    			static void Exit(){
    			}
     
     
     
     
    			}//end class
    Last edited by block g raptor; April 21st, 2010 at 05:38 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Keyboard.class error

    You can never take input from keyboard as you have done in your program. Do
    Scanner s= new scanner(System.in);
    String Name=s.nextline();
    This is my opinion, may someone knows more better.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Keyboard.class error

    I'm not familiar with the Keyboard class, it's not in the Java SE API.

    For reading in input from the keyboard, there are three main ways (and several variations/strange ways):

    1. The Scanner class, as pointed out by Brian

    2. Directly reading from the System.in stream

    3. A buffered reader or some other sort of stream input class

    Basically all three methods are variations of number 2, but the Scanner and any BufferedReader class do make reading data much easier than trying to hack your own work-a-rounds

    Personally, I prefer method 1 simply because the Scanner object is such a powerful object and it is directly integrated with the Java Regex library, and even if I don't need that kind of power, it's so simple to use.

Similar Threads

  1. PayCheck class... percision error.. help!
    By ber1023 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 19th, 2009, 03:31 PM
  2. how to know user pressed a key in the keyboard
    By cilang in forum File I/O & Other I/O Streams
    Replies: 16
    Last Post: September 11th, 2009, 10:08 AM
  3. Truncated class file error
    By Koâk in forum Exceptions
    Replies: 4
    Last Post: June 23rd, 2009, 11:23 AM
  4. How do I fix my program so I can use the keyboard to type in the numbers?
    By rocafella5007 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 29th, 2009, 02:39 PM
  5. How can i control keyboard through programming?
    By Mohd in forum Java Theory & Questions
    Replies: 3
    Last Post: January 5th, 2009, 07:10 AM