Home > Enterprise >  Cannot convert from ArrayList<PVector> to PVector
Cannot convert from ArrayList<PVector> to PVector

Time:12-03

I am working on an ArrayList of PVector, and then I want to do an ArrayList of the ArrayList I was creating.

So when I tried to enter the ArrayList of the ArrayList, it showed the error: Cannot convert from ArrayList<PVector> to PVector I was wondering maybe I need to add into the second ArrayList, but I am not sure how the syntax is and I tried different combinations which were not working. Does anyone knows how can I put an ArrayList of the ArrayList to work?

So here are part of my codes

//position variable for pointSphere
float x;
float y;
float z;

//arraylist of arraylist
ArrayList<ArrayList <PVector>> sphereList = new ArrayList<ArrayList<PVector>>();
//ArrayList<PVector><ArrayList <PVector>>> sphereList = new ArrayList<PVector><ArrayList<PVector>>(10);
//ArrayList<PVector<ArrayList <PVector>>> sphereList = new ArrayList<PVector<ArrayList<PVector>>>(10);
//ArrayList<ArrayList <PVector>><PVector> sphereList = new ArrayList<ArrayList<PVector>><PVector>(10);
//ArrayList<ArrayList <PVector> <PVector>> sphereList = new ArrayList<ArrayList<PVector><PVector>>;


//empty arraylist
ArrayList<PVector> sphere1 = new ArrayList<PVector>();


void setup() {
  size(1920, 1080, P3D);
  pointSphere(270, 27, 27);
}

void draw() {
  background(0);

  pushMatrix();
  translate(500, 500, 100);
  for (int i = 0; i < sphere1.size(); i  ) {
    PVector v1;
    v1 = sphere1.get(i);

    stroke(255);
    strokeWeight(random(2, 10));
    point(v1.x, v1.y, v1.z);
  }
  popMatrix();

  for (int i = 0; i < sphereList.size(); i  ) {
    PVector v3;
    v3=sphereList.get(i);
    point(v3.x, v3.y, v3.z);
  }
}


void pointSphere (float r, float uAmount, float wAmount) {
  for (float u= 0; u < 180; u  = 180/uAmount) {
    for (float w = 0; w < 360; w  = 360/wAmount) {

      //define PVector
      PVector vS1 = new PVector(r*sin(radians(u))*cos(radians(w)), r*sin(radians(u))*sin(radians(w)), r*cos(radians(u)));
      //storing the location of Pvector into sphere1
      sphere1.add(vS1);
      sphereList.add(sphere1);
    }
  }
}

So the error code is v3=sphereList.get(i); and I couldn't figure out how to solve it when the I was trying to rewrite the syntax for ArrayList of ArrayList.

CodePudding user response:

You pointed your own error out in your code:

//arraylist of arraylist
ArrayList<ArrayList <PVector>> sphereList = new ArrayList<ArrayList<PVector>>();

v3=sphereList.get(i); just gets the inner ArrayList at index i.

  • Related