• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Test  RSS feed

 
anirban nag
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!