cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.StringIndexOutOfBoundsException: String index out of range: 8

Former Member
0 Kudos

Hi Friends,

I have a search window ,in one I/P Field i entered * and kept the default max hits to display as 100 records(This can be changed).

Now when i click on Search i get 100 records being displayed,later when i change it to 150,200 Hits i am able to get them displayed(Records).

But when i enter value greater than 200(i had entered 220) i am getting the following exception.

java.lang.StringIndexOutOfBoundsException: String index out of range: 8

Can anyone please help me out to resolve this issue.

Thanks and regards,

Chandrashekar.

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

hi chand,

your issue is:

java.lang.StringIndexOutOfBoundsException:

1.Actually you are searching & displaying the documents from a window contains list of all documents.

2. At the same time you can able to get X number of documents depends upon the users requirements.

3. When user enters Maximum, you caught an exception,

so, thing is for value more than 200 you caught an exception

so in a window, it may contain less number of document, than you mentioned (i.e. Number of documents to be displayed....)

Former Member
0 Kudos

Hi Chandra,

If this didnt solve, let us know the code or the logic, so we can help.

Thanks.

Former Member
0 Kudos

It is better to check the size or length of the string before taking the substring. If you always require a substring with 8th character, you should know what should you do if the string length is not of 8 character, i.e whether to dicard the string or use it as it is. If you still need , take the one which is present. else, dont use substring for that string.

Also make sure that the data is not null.

Hope this will help..

-Shabir.

Former Member
0 Kudos

Hello Chandrashekar,

It looks like in the loop of number of records, you are fetching the record and processing the string either using charAt() method or subString method or any similar method.

But in one of the record string after 200th record is having a string which when you are processing are having length less than 8.

Say : String s = "Correct";

will give StringIndexOutOfBoundsException: String index out of range: 8 as the length is only 7 and you are cheking for char at position 8.

Just check the processing you are doing within the record loop and also the records.

Hope this helps.

Former Member
0 Kudos

Hi Shabir,

Yes whatever you said is absolutely correct,i have cross checked my application and what you said seems to be correct.

But now how do i overcome this issue?

The stack trace for your information is:

java.lang.StringIndexOutOfBoundsException: String index out of range: 8

at java.lang.String.substring(String.java:1683)

Please help me to resolve this issue.

Thanks and regards,

Chandrashekar.

nikhil_bose
Active Contributor
0 Kudos

could you post the code along sample data?

nikhil_bose
Active Contributor
0 Kudos

how many records you have actually ? is that beyond 200?

if so, you can raise an exception if user entered number is greater than records available.

e.g: in records node you are getting values


int size = wdContext.nodeRecords.size();
wdComponentAPI.getMessageManager().raiseException("Record "+size+"does not exists", true);

- nikhiL

Former Member
0 Kudos

Hi

Do you set the max allowed number of returns programatically? Is it ab attribute of the system you are using?

regards

yuval

Former Member
0 Kudos

Hi Yuval,

Yes i am setting this 100 as default value,irrespective of user enters value.

I do this programatically.........

How can i resolve this issue?

thanks and regards,

Shekar.