Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: java.lang.StringIndexOutOfBoundsException  (Read 1542 times)
0 Members and 1 Guest are viewing this topic.
deAppel
Favorite member
Member
*

Reputation: 0
HappyFace plants one on you
Offline Offline
Posts: 45
Referrals: 0

Awards
« on: October 24, 2007, 07:28:01 AM »

Code
GeSHi (java):
  1. /*--------------------------------------------------------------------------
  2. //Author List:
  3. //deAppel <Creator> www.engineeringserver.com
  4. //
  5. //Version: V1.0 initial release 24/OCT/2007
  6. //Description:
  7. // An example that creates the "java.lang.StringIndexOutOfBoundsException" on purpose
  8. //Environment:
  9. // This software was developed using Eclipse 3.2.2 and Java 1.6
  10. //Copyright Information:
  11. //Copyright (C) 2007 <Institution><None>
  12. // Do NOT change the code or post it somewhere else
  13. // EXCEPT www.engineeringserver.com without the author(s) (deAppel) permission!
  14. //----------------------------------------------------------------------*/
  15.  
  16. public class StringExceptionDemo {
  17.  
  18.  
  19. public static void main(String[] args) {
  20. String tmp = "This is a String";
  21.  
  22. System.out.println("Length of the string: " + tmp.length());
  23. System.out.println(tmp.substring(5,9)); //Good :: prints out "is a"
  24. System.out.println(tmp.substring(8,17)); //Bad   :: gives: java.lang.StringIndexOutOfBoundsException
  25. }
  26. }
  27.  
  28.  
Created by GeSHI 1.0.7.20

output:

Quote
Length of the string: 16
is a
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 17
   at java.lang.String.substring(Unknown Source)
   at StringExceptionDemo.main(StringExceptionDemo.java:10)
Logged

Earn $0.04 or more for each search you make! http://www.myhpf.co.uk/apply001.asp?Friend=77889

If you need homework help, just post your assignment and i'll code it before your deadline =) i'll provide you "t3h c0d3z" but only if you show me that you have done something and not just ask for me to write everything for you. Just tell us what the problem is and i'm sure we can fix it for you!

I was born into the Hakka lineage, A bloodline that
traces it's roots back to the original Han emperors of
China. During the rise of the 3 Kingdoms (China's
famous warring period), the Hans were overthrown
and exiled. Forced to flee, they headed south finding
refuge within the mountains of Guilin Province where
they lived under their new title, the Hakka and patiently
wait for their chance to return to the throne as the
Sons Of Heaven...
gluk
Member
*

Reputation: 0
Offline Offline
Posts: 22
Referrals: 0

Awards
« Reply #1 on: April 21, 2009, 05:47:47 PM »

The solution for most of the Java related errors can be found at this site: Java errors and solutions.
« Last Edit: April 22, 2009, 12:47:59 PM by HappyFace » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here