Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java.lang exception

Posted on 2002-05-23
7
Medium Priority
?
185 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 300 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…
Suggested Courses

715 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