469,317 Members | 1,774 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,317 developers. It's quick & easy.

simple java compiler error

JavaStudent07
Expand|Select|Wrap|Line Numbers
  1. H:\>c:\j2sdk1.4.1\bin\javac.exe BubbleSort.java
  2.  
  3. H:\>c:\j2sdk1.4.1\bin\java.exe BubbleSort
  4. Please input the name of the file from which the data will be acquired.  Be sure to use the entire path.
  5. h:\Numbers.txt
  6. 67 34 5 6 23 12
  7. 16
  8. First Character: 6
  9. PlaceHolder: 1
  10. Character:7
  11. PlaceHolder: 2
  12. Character:
  13. Final Concatenated Result of While: 67
  14. PlaceHolder: 4
  15. Character:4
  16. PlaceHolder: 5
  17. Character:
  18. Final Concatenated Result of While: 34
  19. PlaceHolder: 7
  20. Character:
  21. Final Concatenated Result of While: 5
  22. PlaceHolder: 9
  23. Character:
  24. Final Concatenated Result of While: 6
  25. PlaceHolder: 11
  26. Character:3
  27. PlaceHolder: 12
  28. Character:
  29. Final Concatenated Result of While: 23
  30. PlaceHolder: 14
  31. Character:2
  32. PlaceHolder: 15
  33. Character:
  34. Final Concatenated Result of While: 12
  35. Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 16
  36.         at java.lang.String.charAt(String.java:460)
  37.         at BubbleSort.Sort(BubbleSort.java:70)
  38.         at BubbleSort.main(BubbleSort.java:14)
  39.  
  40. H:\>
I dont know why the IndexOutOfBoundsException occurred, anybody know a simple solution?(the program is in the works so its a little confusing but post if you need to see it.)
Thanks in advance,
Steve
Mar 5 '07 #1
2 1368
horace1
1,510 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. H:\>c:\j2sdk1.4.1\bin\javac.exe BubbleSort.java
  2.  
  3. H:\>c:\j2sdk1.4.1\bin\java.exe BubbleSort
  4.  
  5. Final Concatenated Result of While: 12
  6. Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 16
  7.         at java.lang.String.charAt(String.java:460)
  8.         at BubbleSort.Sort(BubbleSort.java:70)
  9.         at BubbleSort.main(BubbleSort.java:14)
  10.  
  11. H:\>
Steve
It means you have tried to access a character in a string where the index given is outside the string, e.g. you have a string "hello" and try to index charAt(10).
http://java.sun.com/j2se/1.4.2/docs/...Exception.html

The error is in line 70 of your code !
Mar 5 '07 #2
Ganon11
3,652 Expert 2GB
If you can't fix the problem from horace's help, you should probably provide the context in which you are calling the Sort function (i.e. the lines where you actually call it) and the relevant section in Sort.
Mar 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

73 posts views Thread by RobertMaas | last post: by
1 post views Thread by ptaz | last post: by
4 posts views Thread by 3rdshiftcoder | last post: by
1 post views Thread by Markus Wollny | last post: by
1 post views Thread by hostel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.