The Artima Developer Community
Sponsored Link

Java Answers Forum
Basic variable issue

2 replies on 1 page. Most recent reply: Apr 6, 2010 1:14 AM by Bryn Loftus

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Bryn Loftus

Posts: 3
Nickname: bryn
Registered: Apr, 2010

Basic variable issue Posted: Apr 6, 2010 12:20 AM
Reply to this message Reply
Advertisement
I have a very basic issue- I have a method as follows:

 public void makeBooking(String name, int time)
    {
        bookings[time] = name;
    }


and when I call that method, giving it input of say fred and 2, it says "Error: cannot find symbol - variable fred". For some reason, I can't pass a String argument in- any other argument type seems to work fine however?


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Basic variable issue Posted: Apr 6, 2010 12:53 AM
Reply to this message Reply
Is the String that you're passing in, in quotes? i.e.
    makeBooking("fred", 2);
I'm guessing that you've actually written...
    makeBooking(fred, 2);
In the latter case, the compiler thinks that fred is a variable that holds the actual name that you want to pass in. Other arguments (i.e. numbers) don't require quotes because - for them - it's obvious when you're talking about a value and when you're talking about a varible holding a value.

Alternatively, you could write:
    String fred = "Joe";
    makeBooking(fred, 2);
But that's probably just going to confuse things.

Vince.

Bryn Loftus

Posts: 3
Nickname: bryn
Registered: Apr, 2010

Re: Basic variable issue Posted: Apr 6, 2010 1:14 AM
Reply to this message Reply
Brilliant, thank you! Thats exactly what it was.

Flat View: This topic has 2 replies on 1 page
Topic: deploying java application on linux server Previous Topic   Next Topic Topic: RAM size, CD/DVD

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use