# Problem with "String Index Out Of Bounds Exception"

**URL:** <https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790>\
**Category:** Coding Questions\
**Created:** [June 2, 2019, 9:41pm UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790 "2019-06-02T21:41:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToastyOosty](https://avatars.discourse-cdn.com/v4/letter/t/b3f665/32.png) [@ToastyOosty](https://discourse.processing.org/u/ToastyOosty)\
**Post date:** [June 2, 2019, 9:41pm UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790/1 "2019-06-02T21:41:01Z")

</div>

So I’m writing this code for a small project I’m working and I keep getting the error message “StringIndexOutOfBoundsException: String index out of range: 0”

I won’t post the entire code cause its a bit long but here’s the code of where it happens

```auto
if(pulled100 || pulled200 || pulled300){
      for(int i=0; i<data.getRowCount(); i++){
        for(int j=0; j<int(numDays); j++){
          if(data.getInt(i, "selected")==1){
            value=data.getString(i, finalDate+j+int(slider));
            println(value);
            println(value.length());
            println(value.charAt(0)); //Error message occurs here
            int counter=0;
            while(value.charAt(counter)!='/'){ //If I get rid of the top print statement it occurs here
              counter++;
              pull+=value.charAt(counter);
            }
            fill(black);
            textSize(50);
            text(pull, width/2, height/2);
            strokeWeight(width/200);
            stroke(black);
            point(height*9/10-height*int(pull)/graphY, width/20+j/int(numDays));
          }
        }
      }
    }

```

The console prints out:

> 58//2  
> 5  
> 5
> 
> 0

I’m not sure where the last 0 comes from in the console but the above three are the only print statements I have. If anyone could help me out a little bit that would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 2, 2019, 9:53pm UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790/2 "2019-06-02T21:53:22Z")

</div>

> [@ToastyOosty](#):
>
> while(value.charAt(counter)!=’/’){ //If I get rid of the top print statement it occurs here  
> counter++;  
> pull+=value.charAt(counter);  
> }

Try

```auto
while(value.length > 0 && value.charAt(counter)!=’/’){ 
  counter++;
  pull+=value.charAt(counter);
}

```

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 2, 2019, 10:00pm UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790/3 "2019-06-02T22:00:20Z")

</div>

Hey There !

I know your new here but remember to format your code!

---

<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:** [June 2, 2019, 11:38pm UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790/4 "2019-06-02T23:38:45Z")

</div>

`if (value != null && !value.empty()) println(value.charAt(0));`

---

<div class="post-metadata">

**Author:** ![ToastyOosty](https://avatars.discourse-cdn.com/v4/letter/t/b3f665/32.png) [@ToastyOosty](https://discourse.processing.org/u/ToastyOosty)\
**Post date:** [June 3, 2019, 12:55am UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790/5 "2019-06-03T00:55:52Z")

</div>

Okay I will definitely do that next time thanks!

---

<div class="post-metadata">

**Author:** ![ToastyOosty](https://avatars.discourse-cdn.com/v4/letter/t/b3f665/32.png) [@ToastyOosty](https://discourse.processing.org/u/ToastyOosty)\
**Post date:** [June 3, 2019, 12:57am UTC](https://discourse.processing.org/t/problem-with-string-index-out-of-bounds-exception/11790/6 "2019-06-03T00:57:12Z")

</div>

Okay that seemed to do the trick, thank you!
