Solved

java.lang exception

Posted on 2002-05-23
7
161 Views
Last Modified: 2010-03-31
Hi

i have encountered this problem and am still looking for a solution. hopefully someone could provide me with a reference site or some brief explanation for the following exception.

>>> compile:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -632
at java.lang.StringBuffer.substring(StringBuffer.java:778)
at fileread.main(getDirFile.java:89)


getDirFile is a class of mine. please help, thanks.

Please email to: garywhw1@yahoo.com thanks alot
0
Comment
Question by:garywhw
  • 4
  • 2
7 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 7029365
 This means that you are trying to access a character of a String that is not available. For instance if you have the String: "hello there" and you are trying to access the 15th character then it will throw the above exception since the "hello there" string is less than 15 characters long.

  WHat I assume you are doing is trying to get the substring from/to a given position that does not exists. If you post some part of your code we can help you more.

  Hope it helps.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7029375
check your getDirFile() method. at line 89 you are trying to call substring() method of a string buffer with incorrect parameters. This means that one of the parameters used to call substring() method is negative value
0
 

Author Comment

by:garywhw
ID: 7031133
You have been helpful to me. thanks for your reply that i had eventually resolved my problem. :) you are great.

the problem lies because the substring returns a negative value. ie, -1. it returns -1 because the indexOf cannot find the parameter required anymore. the way to resolve the problem is :

test: do
{
substring (first, last)
if last = -1
{
   break test;
}
}
while (..)

you strike me with the idea to look into the substring() for the problem. thanks, although you didnt solve the entire problem of mine, you are definately worthy of the 100 points.

can i have your email so that i can send you question. :)
from garywhw1@yahoo.com

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:garywhw
ID: 7031142
You have been helpful to me. thanks for your reply that i had eventually resolved my problem. :) you are great.

the problem lies because the substring returns a negative value. ie, -1. it returns -1 because the indexOf cannot find the parameter required anymore. the way to resolve the problem is :

test: do
{
substring (first, last)
if last = -1
{
   break test;
}
}
while (..)

you strike me with the idea to look into the substring() for the problem. thanks, although you didnt solve the entire problem of mine, you are definately worthy of the 100 points.

can i have your email so that i can send you question. :)
from garywhw1@yahoo.com

0
 

Author Comment

by:garywhw
ID: 7031145
sorry venci75
i was new to this exchange program. i thought that i could give both of you 100 points. ie, 100 points each although it means that i will have less points. you guys had helped me alot. i will definately repay the point to you next time. i am really sorry.

i hope that you will get this 100 points... i am giving it to you too.

i hope i can help although i am new to java. but, God bless you in your career path. God bless the "submit"
0
 
LVL 35

Expert Comment

by:girionis
ID: 7031443
 We are glad we helped. I will send you an e-mail with my e-mail address, even though I think it is betetr to post questions here (even with 0 points) since:

a) other people can help you as well in areas that I might not be able to help you
b) other people can see the solutions and learn from them
0
 

Author Comment

by:garywhw
ID: 7031532
Hi girionis

you are very right and i will try to post my questions here next time. hope that you will get a prosporious career path ahead.

take care,
God bless :)

GaryW
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 52
even odd program using while loop 3 40
eclipse buid path vs tomcat lib path 10 23
JavaFX TableView not displaying correctly 3 18
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question