Solved

java.lang exception

Posted on 2002-05-23
7
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

734 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