For loop iteration won't function correctly

Closed
zlloyd1 Posts 10 Registration date Tuesday December 11, 2012 Status Member Last seen February 4, 2013 - Feb 1, 2013 at 06:36 PM
shoaibista Posts 8 Registration date Friday May 24, 2013 Status Member Last seen May 27, 2013 - May 24, 2013 at 11:07 AM
Hello,
I am trying to make this pie chart program work in NetBeans 7.2.1, but it won't compile for a reason I cannot grasp....
This is the block of code that is creating issues:

for (int i = 0; i < values.size(); i++) {
                g2d.setColor(colors.get(i));

and this is the errors I am getting from it:

method setColor in class Graphics cannot be applied to given types;
required: Color
found: Object
reason: actual argument Object cannot be converted to Color by method invocation conversion

Can someone please tell me what is happening here, because this program runs perfectly from the desktop, in the command prompt, but I need it to be in Net5Beans so that I can use it for another program I am working on??
PLEASE HELP ME!!

Related:

3 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 2, 2013 at 02:00 PM
Just from few lines one reason could be that "colors.get(i)" is object that you may have to explicitly cast as Color
g2d.setColor((Color)colors.get(i));
0
zlloyd1 Posts 10 Registration date Tuesday December 11, 2012 Status Member Last seen February 4, 2013
Feb 2, 2013 at 07:56 PM
@rizvisa1,
I figured that as well, but what was confusing me was that this EXACT code ran fine when I compiled and ran it from the command prompt, but had issues when I sposed the code into NetBeans, and that was freaking me out a bit??
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 2, 2013 at 08:29 PM
could jre be an issue ?
0
zlloyd1 Posts 10 Registration date Tuesday December 11, 2012 Status Member Last seen February 4, 2013
Feb 2, 2013 at 09:09 PM
I don't believe so, I have the latest run-time environment installed, if I am not mistaken....
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 2, 2013 at 09:16 PM
i would uninstall and re install netbeans, if i were you. You can use eclipse too
0
zlloyd1 Posts 10 Registration date Tuesday December 11, 2012 Status Member Last seen February 4, 2013
Feb 3, 2013 at 12:49 AM
I( may end up doing that, as soon as I am sure that it is not something wrong with the code!!
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 3, 2013 at 06:57 AM
Since you said code works in desktop and only in IDE it is causing issue, I dont think any thing is wrong with code. Some how IDE is corrupted to some extent or using different java version. See if this helps
http://forums.netbeans.org/ptopic6210.html
0
shoaibista Posts 8 Registration date Friday May 24, 2013 Status Member Last seen May 27, 2013
May 24, 2013 at 11:07 AM
g2d.setColor((Color)colors.get(i));

Try this.....
This is called downcasting
0