• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can't find symbol variable get - PLEASE HELP!!!

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does this not work? I am having problems with the buypack method.



Thank you!!!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Sorry it has taken so long to reply.

If "get" means a method, it should have round brackets (). It should probably have an argument or arguments too.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you might do well to lose one ( before packets.
 
Carmel Leaning
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks for replying so quickly,

I did that now it is saying cannot find symbol - method get()

Is there another way of writing if a flavour that is entered as a string isn't equal to the flavour declared in the packets then it's null... display error message??

Thanks
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First things first: get the method working at all, then refine it later.

What's packets? Is it an array? Has the Packet class got a get() method? What parameters does that get() method require?
Or is there some sort of Map which requires the String called flavour be passed to its get() method?
 
Carmel Leaning
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the packet is in an arraylist, which links up to another class called packofcrisps.

I have done a get method somewhere else in the coding to get the user to enter a flavour and then the machine will see how many of that flavour there are and that works.

Just this one that is being apain, I took that line of coding out and everything else in that method works fine.

Driving me nuts I tell you

Any ideas?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList? Now I know where I am. The get method of the List interface takes an int parameter, so you would have to try packets.get(index).something().
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And were you taught to use a for loop with an index for iterating an ArrayList? When I was at your stage I was taught to use an Iterator. You can see examples here.

Actually, close examination of that last link suggests you are in fact correct to use a straight for-loop for ArrayList.
[ November 07, 2008: Message edited by: Campbell Ritchie ]
 
Carmel Leaning
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did that ((packets.get(index)).getFlavour().equals(flavour))

What to know is how I say not equals, that says if the packet flavour is equals to the flavour entered then display message. how do I say if the packet flavour is NOT equals to the flavour entered?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think the bit about if (!...equals(null)) will do what you want.
 
Carmel Leaning
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for trying, it still won't do what I want it to do.

Yeah we have just started to learn about Iterators but I am not good at them yet, I think I am going to have to learn it as it is as I can't seem to find a solution and it needs to be handed on Monday,

Bugger..

Thanks anywho
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course it won't work; the loop is up the creek.

You need the RandomAccess interface to show as evidence that you are right to use an index rather than an Iterator.

I am busy now, so I shan't be here for an hour or two. During which time you curse the computer as much as you like, have a cup of tea, get a pencil and paper and write down in words of one syllable what you want to do in that method. Then refine each part in terms the computer can understand. Remember a computer program takes what you tell it literally. That's called pseudo-code.

Is there any risk of null values in your ArrayList? If there is, when you call get() and put a . after it, you will get an Exception.
And don't call equals(null). "null" is a reference and there is only one "null" on your computer, so you can say "== null" or "!= null."
 
Carmel Leaning
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ha ha I probably will end up shouting at it!

Changed it



Now it is saying it can't have an else with an if.. ca't win !! Ha ha!
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joanne has told you how to get out of the if-else problem.

But you really need to work out what that method is supposed to do and how to do it.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume by the lack of replies that you have now got it working perfectly?

. . .
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When it gives you a compiler error, it will tell you the line where things appear to be wrong. This information is EXTREMELY useful in determining the problem. In the future, please post the entire text of the error message.

If you look at your 'if' statement closely, you have this:

That semicolon on that line closes out the 'if' with an empty block. So when you hit that last 'else', indeed there is no matching 'if'.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by myself:
I presume by the lack of replies that you have now got it working perfectly?

. . .



Did you get it working?
 
Carmel Leaning
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, yes I did fred rosenberger was right I did but a ';' where there shouldn't be one and took that away.... and it works

Thanks for all your help guys!
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done getting it to work
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic