This site requires JavaScript, please enable it in your browser!
Greenfoot back
Pointifix
Pointifix wrote ...

2014/3/4

ForEach Problem

Pointifix Pointifix

2014/3/4

#
Hi Guys, me again. I got this little problem im sure you know the answer why the compiler doesnt like it ;)
1
2
3
4
5
Violator violator = ((Violator)getObjects(Violator.class));
         
        violator.schock = true;
         
        for(Violator obj : violator)obj.schock = true;
danpost danpost

2014/3/4

#
'getObjects' returns a List object not an individual object (which is what you are trying to set the field to). If you are trying to set the 'schock' field in all Violator objects to 'true', then:
1
for (Object obj : getObjects(Violator.class)) ((Violator)obj).schock = true;
or
1
for (Violator violator : (java.util.List<Violator>)getObjects(Violator.class)) violator.schock = true;
The first one typecasts the objects from the list, the second typecasts the List itself.
Pointifix Pointifix

2014/3/4

#
k jeah but i do not even find whats wrong, sry
erdelf erdelf

2014/3/4

#
Edit: ignore that, danpost edited his post
Pointifix Pointifix

2014/3/4

#
exactly danpost, thanks alot :) you seam to be online on greenfoot all day ;D
danpost danpost

2014/3/4

#
Pointifix wrote...
you seam to be online on greenfoot all day ;D
Well, I take care of my elderly mother at home. So, my spare time, which is intermittent, but often, is TV, computer or jigsaw puzzle (wish I had a pool table, though).
Pointifix Pointifix

2014/3/4

#
then answering questions on greenfoot and doing nice projects as you do is a very good and sensefull time distribution
8bitcarrotjuice 8bitcarrotjuice

2014/3/4

#
Dan, do you have a job as a programmer? If so, what level of expertise are you required to know inorder to get employed? The reason I ask is that I want to become a programmer. I 'excel' at mathematics (for my age) as I am one of the best in my year, as I know you need to know maths well to program, but I do not know what level of skill I need to acquire, and what topics I need to cover. I have yet to cover networking, working with sql and rss in Java, and some other major topics. I am currently working on Graphics2D and BufferedImage along with other classes to make a paint program like GIMP (but worse as it is in Java and I lack the skill & time to push it to that level). So yeah. And another question: are there any 'professional' painting programs made in Java? Thanks in advance. PS Other people can give their opinion too!
Pointifix Pointifix

2014/3/4

#
becoming a programmer must be cool i think, specially a game developer ;) but i dont think there are so many programmers needed out there.
8bitcarrotjuice 8bitcarrotjuice

2014/3/4

#
I know it is a very saturated market, but I want to become one. And not in gaming development, that is even more saturated (and is limited in Java; use c++ for that).
Pointifix Pointifix

2014/3/4

#
c++ for game development, i heard java is better for this, but i would like that cause im better in c/c++ then in java ;)
danpost danpost

2014/3/4

#
8bitcarrotjuice wrote...
Dan, do you have a job as a programmer?
I never held a job as a programmer (though I have done a little this and that for places I have worked at, as well as some personal requests). I do not have any formal training, per se, in programming. Ninety-nine percent of my programming knowledge I have acquired on my own (GWBasic>QBasic>Assembly>VisualBasic>Java -- I have touched on HTLM and javascript as well).
You need to login to post a reply.