• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StringIndexOutOfBoundsException: length=0; index=-1

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a calculator project.
My plus-button has a few statements.

-Statement 1 avoids typing 2 operators in a row.

-Statement 2 adds a "+" sign if there is no previous "+" sign.

-The last is to avoid adding a "+" sign while the <calculation> string is empty(this string holds all user input).

It gives me an "java.lang.StringIndexOutOfBoundsException: length=0; index=-1"
error whenever I tap the plus-button. Someone know how to fix it?

 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this related to
https://coderanch.com/t/687289/Android/mobile/Android-Studio-Calculator-Project-whats ?

Are you using the log methods as stated in the previous link? Your can read more about these log methods here https://developer.android.com/reference/android/util/Log.html
 
ian bilgaen
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes just updated it and now the only problem lies with the .isEmpty() method on the calculation string.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using the log methods as noted in the previous post? These methods can help you see values and more in your logs as you go.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Android supports 'endswith' as noted here
https://developer.android.com/reference/java/lang/String.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic