AndroidStudio 3D figure

I am having troubles drawing in 3D in AndroidStudio. This is my code in processing:

import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.math.waves.*;
import toxi.processing.*;
import processing.serial.*;

ToxiclibsSupport gfx;

void setup() {
  size(600,600,P3D);
  gfx=new ToxiclibsSupport(this);
  
  background(255);
  noStroke();
  fill(200,200,200);
}

void draw() {
  
  Quaternion RotQ = new Quaternion(1,0,0,0);
  float qMatrix[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  PMatrix M1 = getMatrix();
  
  RotQ = new Quaternion(0.7, 0.5, 0.4,0.316227766);
  
  RotQ.toMatrix4x4().toFloatArray(qMatrix);
  
  M1.set(
      qMatrix[0], 
      qMatrix[1], 
      qMatrix[2], 
      qMatrix[3], 
      qMatrix[4], 
      qMatrix[5], 
      qMatrix[6], 
      qMatrix[7], 
      qMatrix[8], 
      qMatrix[9], 
      qMatrix[10], 
      qMatrix[11], 
      qMatrix[12], 
      qMatrix[13], 
      qMatrix[14], 
      qMatrix[15]
      );
      
      AABB cube;
      
      background(255);

      // Set some mood lighting
      ambientLight(128, 128, 128);
      directionalLight(128, 128, 128, 0, 0, 1);
      lightFalloff(1, 0, 0);
      lightSpecular(0, 0, 0);

      // Get to the middle of the screen
      translate(width/2,height/2,0);

      // Do some rotates to get oriented "behind" the device
      rotateX(-PI/2);

      // Apply the Matrix that we generated from our IMU Quaternion
      applyMatrix(M1);
      
      //elk vlak ander kleur       
      directionalLight(0, 128, 255, 0, -1, 0); 
      directionalLight(204, 0, 0, 0, 1, 0); 
      directionalLight(0, 0, 0, -1, 0, 0); 
      directionalLight(255, 255, 0, 1, 0, 0); 
      directionalLight(255, 128, 0, 0, 0, -1);
      directionalLight(0, 255, 0, 0, 0, 1);

      // Draw the Cube from a 3D Bounding Box
      cube=new AABB(new Vec3D(0,0,0),new Vec3D(100,100,100));
      gfx.box(cube);
      
      //sphere(100);
      
      
}

When I convert this code to AndroidStudio, somehow ‘size(600,600,P3D);’ disappears. When running my code, my figure is just 2D instead of 3D. I think this is because this size(600,600,P3D); isn’t there, but when I add this line I get a null pointer error and my app crashes.
How can I display my 3D figure as a 3D figure in AndroidStudio?

An extra function is made in AndroidStudio (the function public void settings) where size is used:

public void settings() {  size(400,400,P3D); }

So size and P3D are being used and still my figure isn’t in 3D, why is this?
(So it doesn’t disappear, however it is not working apparently.)

If it would be necessary, here is the full code of my sketch in AndroidStudio:

package com.nordicsemi.nrfUARTv2;

import android.content.Intent;

import processing.core.PApplet;
import processing.core.PMatrix;
import toxi.geom.AABB;
import toxi.geom.Quaternion;
import toxi.geom.Vec3D;
import toxi.processing.ToxiclibsSupport;
//import processing.serial.*;


public class sketch_sphere extends PApplet {

ToxiclibsSupport gfx;
Quaternion Rotq = new Quaternion(1/2, 87/100, 0, 0);

    public void settings() {
        size(400,400,P3D);
    }

public void setup() {

        gfx=new ToxiclibsSupport(this);
  background(255);
  noStroke();
  fill(300,300,300);
}

public void draw() {

  float qMatrix[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  PMatrix M1 = getMatrix();

    //Quaternion RotQ = new Quaternion(0.4f, 0.5f, 0.7f,0.316227766f);
  
  Rotq.toMatrix4x4().toFloatArray(qMatrix);
  
  M1.set(
      qMatrix[0], 
      qMatrix[1], 
      qMatrix[2], 
      qMatrix[3], 
      qMatrix[4], 
      qMatrix[5], 
      qMatrix[6], 
      qMatrix[7], 
      qMatrix[8], 
      qMatrix[9], 
      qMatrix[10], 
      qMatrix[11], 
      qMatrix[12], 
      qMatrix[13], 
      qMatrix[14], 
      qMatrix[15]
      );
      
      AABB cube;
      
      background(255);

      // Set some mood lighting
      ambientLight(128, 128, 128);
      directionalLight(128, 128, 128, 0, 0, 1);
      lightFalloff(1, 0, 0);
      lightSpecular(0, 0, 0);

      // Get to the middle of the screen
      translate(width/2,height/2,0);

      // Do some rotates to get oriented "behind" the device
      rotateX(-PI/2);

      // Apply the Matrix that we generated from our IMU Quaternion
      applyMatrix(M1);
      
      //directionalLight(0, 255, 0, 0, -1, 0);
      //sphere(130);

    //elk vlak ander kleur
    directionalLight(0, 128, 255, 0, -1, 0);
    directionalLight(204, 0, 0, 0, 1, 0);
    directionalLight(255, 0, 0, -1, 0, 0);
    directionalLight(255, 255, 0, 1, 0, 0);
    directionalLight(255, 128, 0, 0, 0, -1);
    directionalLight(0, 255, 0, 0, 0, 1);

    // Draw the Cube from a 3D Bounding Box
    cube=new AABB(new Vec3D(0,0,0),new Vec3D(50,50,50));
    gfx.box(cube);
}


    public void setQuaternion(float[] quat_array){
        Rotq = new Quaternion(quat_array[0], quat_array[1], quat_array[2], quat_array[3]);
        redraw();
    }
}



So why is this not in 3D?

Could it be because of the redraw when I get new quaternions? That I have to add something more, instead of just redraw. Because, whathever quaternions I give as first, the first image is always a nice sphere. So I think that it could be because of the redraw?