471,852 Members | 1,281 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

"main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2

Hello,

I have a question about this error:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2

I am doing my java development in IBM Rationale eclipse. I am compiling and running everything just fine. When I try to run my application on a commandline I get this error. I don't know why this is happening since it is working perfectly in eclipse. I am running a .bat file and here is the .bat file:

@echo on
rem ---------------------------------------------------------------------------
rem Script for launching Translation Application
rem
rem Environment Variable Prequisites
rem
rem
rem ---------------------------------------------------------------------------
cls


SET DERBY_INSTALL=C:\Translation\Cloudscape_10.1
SET TRANSLATION=C:\Translation
set CLASSPATH=%DERBY_INSTALL%\lib\derby.jar;%DERBY_INS TALL%\lib\derbytools.jar;%TRANSLATION%\lib\Transla tion.jar;

echo %CLASSPATH%

C:\Translation\jdk\jre\bin\java -classpath %CLASSPATH%;C:\Translation\Conversions src.utilities.DataConversionUtilityDaily

pause

Can someone help me find out why my program is not running?
Aug 3 '07 #1
6 31812
JosAH
11,448 Expert 8TB
Hello,

I have a question about this error:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2
Most definitely you're trying to access a charAt(-2) either directly or indirectly.
The exception message also tells you on which line the error happened; read
carefully through the stack trace and you'll find it.

kind regards,

Jos
Aug 3 '07 #2
Most definitely you're trying to access a charAt(-2) either directly or indirectly.
The exception message also tells you on which line the error happened; read
carefully through the stack trace and you'll find it.

kind regards,

Jos
Hi, I looked at line that the errors is on. Here is the code that is erroring:

sqlStatement.append(text.deleteCharAt(text.length( )-2));

but it is not erroring in eclipse. This line of code doesn't error in eclipse it runs perfectly. So I don't understand the difference in why in will work in eclipse but not on the command line.
Aug 3 '07 #3
JosAH
11,448 Expert 8TB
Hi, I looked at line that the errors is on. Here is the code that is erroring:

sqlStatement.append(text.deleteCharAt(text.length( )-2));

but it is not erroring in eclipse. This line of code doesn't error in eclipse it runs perfectly. So I don't understand the difference in why in will work in eclipse but not on the command line.
As an intermediate conclusion all I can say is that your string length is zero.
Don't blame Eclipse or anything else but sprinkle in a few System.out.println()
method calls at certain positions you don't trust. btw, what's the type of 'text'?

kind regards,

Jos
Aug 3 '07 #4
As an intermediate conclusion all I can say is that your string length is zero.
Don't blame Eclipse or anything else but sprinkle in a few System.out.println()
method calls at certain positions you don't trust. btw, what's the type of 'text'?

kind regards,

Jos
I am creating a sql statement and I am deleting the last comma from the text. The text is a comma ",". I guess my question is why is that same java statement working in eclipse and it errors out on the command line. If it compiles and executes in eclipse it should work on the command line right?
Aug 3 '07 #5
JosAH
11,448 Expert 8TB
I am creating a sql statement and I am deleting the last comma from the text. The text is a comma ",". I guess my question is why is that same java statement working in eclipse and it errors out on the command line. If it compiles and executes in eclipse it should work on the command line right?
Yes, right. Do you do anything in Eclipse that you don't do using just java
on your command line? There must be a reasonable explanation for this.

kind regards,

Jos
Aug 3 '07 #6
[quote=JosAH]Yes, right. Do you do anything in Eclipse that you don't do using just java
on your command line? There must be a reasonable explanation for this.

kind regards,

Jos[/QUOTE

I copied over the same jre that comes with the eclipse. Do you think that could have anything to do with? I did a test and I compiled a simple HelloWorld program in the same project as my application. I ran the HelloWorld file on the command line and it worked. So I don't know what is going wrong. My application is running just fine in eclipse on my laptop and now I need to run it on a test server and it is not working.
Aug 3 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by tiyaramunna | last post: by
NeoPa
reply views Thread by NeoPa | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.