Solved

java.lang exception

Posted on 2002-05-23
7
159 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now