aspose file tools*
The moose likes Beginning Java and the fly likes can't find symbol variable get - PLEASE HELP!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can Watch "can New topic
Author

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

Carmel Leaning
Greenhorn

Joined: Nov 07, 2008
Posts: 7
Why does this not work? I am having problems with the buypack method.



Thank you!!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
And you might do well to lose one ( before packets.
Carmel Leaning
Greenhorn

Joined: Nov 07, 2008
Posts: 7
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Nov 07, 2008
Posts: 7
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Nov 07, 2008
Posts: 7
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
I don't think the bit about if (!...equals(null)) will do what you want.
Carmel Leaning
Greenhorn

Joined: Nov 07, 2008
Posts: 7
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Nov 07, 2008
Posts: 7
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!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
I presume by the lack of replies that you have now got it working perfectly?

. . .
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

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'.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Nov 07, 2008
Posts: 7
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Well done getting it to work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't find symbol variable get - PLEASE HELP!!!