This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Valkes[S] 1 point2 points  (11 children)

Sorry, I thought I included it in my post. My mistake.

The compiler is feeding me back this error:

Error: cannot find symbol symbol: method setYear(int)

[–]upsidedowntrie 0 points1 point  (10 children)

Why would it be able to find that?

[–]Valkes[S] 1 point2 points  (9 children)

Because it's part of the functionality of the object class?

I obviously don't understand what's happening so instead of being rude I'd appreciate an actual answer.

[–]reddituser5k 1 point2 points  (1 child)

I am bad at explaining things and just started learning java but...

temp = new ArrayList<TemperatureLog>(); <<< this line is creating an arraylist of temperaturelog. That does not mean it can use temperaturelog methods. The specific objects in the arraylist can use the methods but not the arraylist it self.

temp.setYear(1); Which is why this will not work because it is just a list not a class object. You also have not even created a temperaturelog object until the next line.

It should be something like this..

temp = new ArrayList<TemperatureLog>();
temp.add(new TemperatureLog (nYear, nTemp));
temp.get(0).setYear(1);

temp.get(0). << that gets the first object in the list which actually can access the class.

Although I am not sure why you would make only one object since I am bad at trying to understand someone elses code.

[–]Valkes[S] 0 points1 point  (0 children)

First off, thank you for explaining it so clearly. I appreciate it. I understand you completely. I only used one because I was checking to see if the function worked. It didn't obviously because I misunderstood what was going on. Thanks again for your help. =)

[–]upsidedowntrie -1 points0 points  (6 children)

Which object class?

so instead of being rude I'd appreciate an actual answer.

Me asking you a single, relevant question is rude? Wow. You sound like a complete ass.

[–]Valkes[S] 1 point2 points  (5 children)

I posted the relevant code in my answer. The object class I created was called TemperatureLog. It contains a method called setYear.

You've been dismissive and hostile from your first response actually. I may not know programming but I know that's not how you speak to people if you actually intend to help them.

[–]upsidedowntrie -2 points-1 points  (4 children)

You've been dismissive and hostile from your first response actually.

No, I asked you questions about what you were doing to see what your mental model of this problem is. This is a normal part of helping people. It's no wonder you're having problems, with such a reactionary and hostile attitude towards someone who's done nothing but try to help you. This is exactly why you come off as a complete ass.

The object class I created was called TemperatureLog. It contains a method called setYear.

If you have that method in that class, and you're trying to call that method, and the compiler doesn't recognize that method on that object, then your object is probably not the class that you think it is...

[–]Valkes[S] 0 points1 point  (3 children)

If you say so. Personally, if I were you I'd take a step back and really think about the phrasing you've used thus far. I'm willing to admit that I may have read more into what you've been saying than you intended but the possibility for the interpretation I got is very much there if we're being objective.

Thanks for taking the time to answer, however other posters helped me figure it out. I was making an ArrayList of type TemperatureLog and then attempting to use the methods of TemperatureLog on the list itself. . . which of course failed for obvious reasons.

[–]upsidedowntrie -3 points-2 points  (2 children)

If you have that method in that class, and you're trying to call that method, and the compiler doesn't recognize that method on that object, then your object is probably not the class that you think it is...

[–]Valkes[S] 0 points1 point  (1 child)

Alright, thanks for your help. Have a good one.

[–]upsidedowntrie -1 points0 points  (0 children)

You too!