Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

Unable to retrieve array from other class

$
0
0

Hello! I'm working on a school assignment, it's nearly done but i'm unable to get some array's from the classes I made. I'm building the app for android devices, but I'm fairly sure that has nothing to do with it. The code that doesn't work is in the try block. Since both my classes have the exact same problem I've only included 1 here:

MAIN CLASS:

KnobInitiator ki;
SensorInitiator sen;

void setup() {
  orientation(PORTRAIT);
  size(displayWidth, displayHeight);
  KnobInitiator ki = new KnobInitiator();
  SensorInitiator sen = new SensorInitiator();
  ki.init(this);
  sen.init(this);
}

void draw()
{
  background(255, 255, 255);
  try
  {
  int[] rectVals = ki.getRectVals();//This doesn't work?
  int[] colorVals = sen.getColorVals();//This doesn't work?
  fill(colorVals[0], colorVals[1], colorVals[2]);//Causes app to crash
  rect(rectVals[0], rectVals[1], rectVals[2], rectVals[3]);//Causes app to crash
  }
  catch (Exception ex)
  {
   println("Failed to obtain rectVals.");
  }
}

SECOND CLASS:

import controlP5.*;

public class KnobInitiator
{
  ControlP5 cp5;

  Knob rectX;
  Knob rectY;
  Knob rectW;
  Knob rectH;

  int pvalX= displayWidth/8;
  int pvalY= displayHeight/8;

  //RectVal: widht, height, x, y
  private int[] rectVal;

  void init(PApplet  papp)
  {
  rectVal = new int[] {0, displayHeight/2, 300, 300};
  cp5 = new ControlP5(papp);
  rectX = cp5.addKnob("X")
              .setRange(0, displayWidth)
              .setValue(0)
              .setPosition((1 * pvalX), (0.5 * pvalY))
              .setRadius(displayWidth/8)
              .setDragDirection(ControlP5.HORIZONTAL);
  rectY = cp5.addKnob("Y")
              .setRange(displayHeight/2, displayHeight)
              .setValue(0)
              .setPosition((4 * pvalX), (0.5 * pvalY))
              .setRadius(displayWidth/8)
              .setDragDirection(ControlP5.HORIZONTAL);
  rectW = cp5.addKnob("Width")
              .setRange(1, displayWidth)
              .setValue(0)
              .setPosition((1 * pvalX), (2 * pvalY))
              .setRadius(displayWidth/8)
              .setDragDirection(ControlP5.HORIZONTAL);
  rectH = cp5.addKnob("Height")
              .setRange(1, displayHeight/2)
              .setValue(0)
              .setPosition((4 * pvalX), (2 * pvalY))
              .setRadius(displayWidth/8)
              .setDragDirection(ControlP5.HORIZONTAL);
  }

  void rectX(int x)
  {
    rectVal[0] = x;
  }

  void rectY(int y)
  {
    rectVal[1] = y;
  }

  void rectW(int x)
  {
    rectVal[2] = x;
  }

  void rectH(int y)
  {
    rectVal[3] = y;
  }

  public int[] getRectVals()
  {
   return rectVal;
  }
}

Viewing all articles
Browse latest Browse all 941

Trending Articles