Solved

java.lang exception

Posted on 2002-05-23
7
158 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
Comment Utility
 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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:garywhw
Comment Utility
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
Comment Utility
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
Comment Utility
 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 60
array220 challenge 8 44
countHi2 challenge 7 43
json example 39 110
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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

10 Experts available now in Live!

Get 1:1 Help Now