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 › Splice and new class in Class Array.
Page Index Toggle Pages: 1
Splice and new class in Class Array. (Read 338 times)
Splice and new class in Class Array.
Aug 12th, 2009, 2:33am
 
Hi, world, i have i little probleme with a class array, i have some strange message like "ClassCastException: Ljava.lang.object; cannot be cast to [Ltest_array$myArray....."

I can use splice with an array object?
I make all my code, it's more easy if you want try.

Thank you very munch for your help!
Huh

////////////////MAIN

import processing.opengl.*;
myArray [] ArrayBig = new myArray[3];

void setup(){
 size(800,600,OPENGL);
 background(0);
 mouseX = 40;
 for(int i=0;i<ArrayBig.length;i++){
   ArrayBig[i] = new myArray(Xref+50*i,y);

 }
}

int y = 100;
int x=0;

void draw(){
 background(0);

 for(int i=0;i<ArrayBig.length;i++){
   ArrayBig[i].update(Xref+-2*50+50*i,y);
 }
 change();
}


int Xref = 100;
int multi = 1;

void change(){  
 if(mouseX>Xref){  
   changeRight();
   multi++;
   Xref += 50;
 }
 if(mouseX<Xref-100){  
   changeLeft();
   multi--;
   Xref -= 50;
 }  
}


void changeRight(){
 myArray [] ArrayBig2 = (myArray[]) subset(ArrayBig,1);
 ArrayBig = ArrayBig2;
 myArray [] ArrayBig3 = (myArray[]) append(ArrayBig,new myArray(Xref+-2*50+50*3,y));
 ArrayBig = ArrayBig3;
}

void changeLeft(){
 myArray [] ArrayBig2 = (myArray[]) subset(ArrayBig,3);
 ArrayBig = ArrayBig2;
//My problem is here....
 myArray [] ArrayBig3 = (myArray[]) splice(ArrayBig,(new myArray(Xref+-2*50+50*3,y)),0);
 ArrayBig = ArrayBig3;
}

////////////////CLASS myArray
class myArray{
int R,V,B;
 
 myArray(int x,int y){
   R = round(random(255));
   V = round(random(255));
   B = round(random(255));
   rect(x,y,50,50);
 }

 void update(int x,int y){
   stroke(255);
   strokeWeight(.1);
   fill(R,V,B);
   rect(x,y,50,50);
 }
}

//////////////////////////////////////

Page Index Toggle Pages: 1