Results 1 to 6 of 6
  1. #1
    sjaakie is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default Problem with compiling: cannot be applied to (java.lang.String)

    edit removed
    Last edited by sjaakie; 10-10-2010 at 11:54 AM.

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    your method checkIn wants a Gast object, not a string object!

    (void checkIn(Gast nieuweGast))

    so, change hotel.checkIn("Guido"); to hotel.checkIn(new Gast("Guido"));

  3. #3
    sjaakie is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    thanks a lot, it compiles now! However, it doesnt do what it is supposed to do.

    Now when i start and input 2 it performs the checkIn(new Gast("guido")) and goes to

    Java Code:
    if (kamer1.gast == null) {		
    		kamer1.gast = nieuweGast;
    		System.out.println("Gast " + nieuweGast.naam + " krijgt kamer 1");
    		return;
    		}
    afterwards the menu comes up again, but when i press 2 again, it doesn't go to the second room (kamer). how can this be? the kamer1.gast has the value guido after the first time right? so it is not equal to null. So why then does it still take the first if statement?

    anybody any ideas? thanks a lot!

  4. #4
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    because you create a new hotel:

    Hotel hotel = new Hotel();
    hotel.checkIn("Guido");

    so every time you create a new hotel, you create new kamer1 to kamer4 too (look into your constructor)

  5. #5
    sjaakie is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    ah I see, thanks! Any tips or ideas on how to make it so that it doesn;t create a hotel every time?

  6. #6
    sjaakie is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    Ah i got it, just put it outside the do while loop. thanks guys for your help!

Similar Threads

  1. Replies: 4
    Last Post: 01-29-2010, 09:57 PM
  2. Replies: 3
    Last Post: 12-01-2008, 05:40 AM
  3. Replies: 4
    Last Post: 11-27-2008, 06:09 AM
  4. Replies: 2
    Last Post: 09-18-2008, 07:30 AM
  5. Error: cannot be applied to (java.lang.String)
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •