# Array Index Out of Bounds error on PGraphics.text()

**URL:** <https://discourse.processing.org/t/array-index-out-of-bounds-error-on-pgraphics-text/10239>\
**Category:** Processing.py\
**Created:** [April 13, 2019, 3:28pm UTC](https://discourse.processing.org/t/array-index-out-of-bounds-error-on-pgraphics-text/10239 "2019-04-13T15:28:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 13, 2019, 7:21pm UTC](https://discourse.processing.org/t/array-index-out-of-bounds-error-on-pgraphics-text/10239/2 "2019-04-13T19:21:21Z")

</div>

This is a Jython’s major shortcoming when dealing w/ Java’s overloaded methods & constructors: ☕

> [@Issue when porting an example sketch from the Hemesh library to Python mode](https://discourse.processing.org/t/issue-when-porting-an-example-sketch-from-the-hemesh-library-to-python-mode/8570/6):
>
> WB\_Render3D::drawTriangle() got 6 overloaded versions of it: And outta those 6, there are 2 w/ the 1 parameter signature that is a container: And 1 w/ 1 parameter that is a single WB\_Triangle: Method WB\_IsoSurface::getTriangles() returns a List\<WB\_Triangle\>: But if we call print type(triangles), we’ll find out its actual datatype is: \<type 'org.eclipse.collections.impl.list.mutable.FastList'\> [Eclipse.org/collections/javadoc/9.0.0/org/eclipse/collections/impl/list/mutable/FastLi…](http://Eclipse.org/collections/javadoc/9.0.0/org/eclipse/collections/impl/list/mutable/FastList.html)

You see, method **text()** got 9 overloaded signatures: 🙈

> **[text() / Reference](https://processing.org/reference/text_.html)**
>
> Draws text to the screen. Displays the information specified in the first parameter on the screen in the position specified by the additional parameters. A default font will be used unless a font is s…

At `self.graphics.text(self.character[x][y], int(x * tileSize), int(y * tileSize), int(tileSize), int(tileSize))`, you’re attempting to use **text()**'s 7th sig w/ 5 parameters:  
**text** (str, x1, y1, x2, y2).

But I’m highly suspicious Jython actually invokes **text()**'s 4th sig instead, which also got 5 parameters:  
**text** (chars, start, stop, x, y).

| | |
| --- | --- |
| chars | char: the alphanumeric symbols to be displayed |
| start | int: array index at which to start writing characters |
| stop | int: array index at which to stop writing characters |

So it seems Jython is passing your _self.character[x][y]_ argument as if it were a Java `char[]` array instead of an actual String! 📿

Unfortunately, Jython doesn’t have any native feature to allow us to forcibly pick a particular overloaded sig of a Java method when its own auto choice fails. 😿

For such cases, our last recourse would be to rely on the Java’s reflection API as I did in the forum post I’ve linked above. 😒

But for your particular case, there’s a much easier workaround: Use Java’s own String datatype: 💡  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html)

```python
from java.lang import String

def set(self, x, y, character):
    self.character[x][y] = String(character)
    self._update.append((x,y))

```

---

_[View the full topic](https://discourse.processing.org/t/array-index-out-of-bounds-error-on-pgraphics-text/10239)._
