Home>

I want to find out the cause of the exception.

Error message

When using tweak mode in the processing editor,
On the 22nd line of the source code below

ArrayIndexOutOfBoundsException


Has come out.

Passing the length of the array raised an exception, so
When the number of arrays was unavoidable, no exception occurred.

In normal rendering execution that is not in tweak mode, no exception occurs in the line,
I was able to describe without problems.

I don't know what caused the exception locally.

Applicable source code

numLabelType1 is a PGraphics type.
numImageType1 is a PImage type.

void makeNumLabel () {
  int [] numStrType1and2 = {9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1};// | Single digit label
  int labelHType1 = numStrType1and2.length * numDistType1;
  / *
   -
   -Create Type1 (Numeric label | Large one digit)
   -
   * /
  textFont (HUDFont, fontType1);// --------------------------------- | Decision
  int labelWType1 = floor (textWidth ("0"));/// ---------------------- | Label width | Get the character width of "0" (Rounded down)
  numLabelType1 = createGraphics (labelWType1, labelHType1, P2D);// | Create image frame and render settings
  numLabelType1.beginDraw ();// ------------------------------------ | Draw characters in PGraphics Do
  numLabelType1.background (0);// ---------------------------------- | Image Background | Black
  numLabelType1.textFont (HUDFont, fontType1);// ------------------- | Determining the font to use and the number of points
  numLabelType1.textAlign (LEFT, BASELINE);// ---------------------- | Text alignment | Left/Baseline
  numLabelType1.fill (0, 255, 0);// -------------------------------- |
  // for (int i = 0;i<= numStrType1and2.length-1;i ++)
  for (int i = 0;i<= 23-1;i ++)
  {
    numLabelType1.text (nf (numStrType1and2 [i], 1), 0, i * -numDistType1 + labelHType1);
  }
  numLabelType1.endDraw ();// -------------------------------------- |
  numImageType1 = numLabelType1.get ();// -------------------------- |
}
Supplemental information (FW/tool version etc.)

processing 3.4

  • Answer # 1

    Exchanging the order no longer causes an exception.

    This function is executed in setup (),
    Inside setup (),

    // correct
    size ()
    makeNumLabel ()


    // Incorrect
    makeNumLabel ()
    size ()


    I was trying.

Related articles