We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Object to int conversation and drawing
Page Index Toggle Pages: 1
Object to int conversation and drawing (Read 723 times)
Object to int conversation and drawing
Dec 23rd, 2008, 11:54am
 
I have the following Object v : [[0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4], [0, 0, 0, 4, 4, 4, 4, 4, 6, 2, 2, 3], [0, 4, 4, 4, 4, 4, 4, 4, 6, 2, 2, 2]]

println( v.get(1))  
----
gives [0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 4]

Vector v1 = (Vector) v.get(1);
println(v1.get(5));  
----
gives 4

line (v1.get(0),v1.get(1),v1.get(2),v1.get(3));
----
gives
The method line(float,float,float,float) in the type PApplet is not applicable for the arguments(Object, Object, Object, Object)


Please help me how to draw a line

Re: Object to int conversation and drawing
Reply #1 - Dec 23rd, 2008, 1:58pm
 
You need to cast it after retrieving from a container.  It's a big pain when generics can't be used.

Pain:

line ((Float)v1.get(0),(Float)v1.get(1),(Float)v1.get(2),(Float)v1.get(3));


Re: Object to int conversation and drawing
Reply #2 - Dec 23rd, 2008, 5:51pm
 
thank you, but it says:

Exception in thread "Animation Thread" java.lang.ClassCastException: java.lang.Integer
at getting_data.setup(getting_data.java:53)
at processing.core.PApplet.handleDraw(PApplet.java:1383)
at processing.core.PApplet.run(PApplet.java:1311)
at java.lang.Thread.run(Thread.java:613)


- really pain
Re: Object to int conversation and drawing
Reply #3 - Dec 23rd, 2008, 6:20pm
 
Try this instead, then.

Modified pain:

line ((Integer)v1.get(0),(Integer)v1.get(1),(Integer)v1.get(2),(Integer)v1.get(3));
Re: Object to int conversation and drawing
Reply #4 - Dec 24th, 2008, 6:16am
 
This type of pain is much better and works, thank you!
Re: Object to int conversation and drawing
Reply #5 - Dec 24th, 2008, 6:28am
 
No problem.  

Way to reduce the pain is to have a good way to keep track of what goes into the array.  The problem/confusion was caused because the transformation of primitive (int) to wrapper class (Integer) happened by autoboxing magic.

It's usually better to be clear and explicit in these matters.
Page Index Toggle Pages: 1