• 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

String Test

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



now my main question is :

when i'm running this code in jcreator it's showing :

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0

but when i'm running this in command promt there are no exception or error why??

*condition user gives valid input.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anirban nag wrote:when i'm running this code in jcreator it's showing :
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
but when i'm running this in command promt there are no exception or error why??


The only thing I can guess is that either
1. Whatever console jcreator uses isn't connected to System.in (seems odd; but I've never used the product).
2. You aren't entering a character.

Specifically, you need to make sure that line2.length() is > 0 before you try line2.charAt(0).

BTW, 'line2' is not a very good name.

Winston
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thank you for using code tags, but your code would be more lgible if you only used spaces for indenting, and didn’t have so many empty lines.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic