Loading...
Logo
Processing Forum
Hello all,

I've set up an ArrayList of Node class objects. I'm running a simple for loop to grab each one, but when I run this:

Node nm = (Node) nodes.get(m);

if's giving me a ClassCastException saying that PVector cannot be cast into Node. The problem is that I'm not casting PVector and Node is not holding a PVector. 

The other strange part is I have almost the exact same line of code about 10 lines before:

Node nodej = (Node) nodes.get(j);

and it works just fine. 

I know it's hard to give me a specific answer without all of my code. I can dump it here if I need to, but I was just hoping for a first stab at why this might be.

Also, I can call specific Node objects. If I change the "m" to a number : nodes.get(0), it works. What gives?

Thanks.

Justin

Replies(2)

Never mind!

I got it! I missed one of my old code lines that was adding a PVector to the ArrayList instead of a Node. Changed it and I'm good.
If you declared your nodes array list with its type, you wouldn't have been able to add anything else, anyway...
ArrayList<Node> nodes = new ArrayList<Node>();
And it removes the need to cast back the object on get().