By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

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

P: 4
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
Share this Question
Share on Google+
6 Replies


Expert 10K+
P: 11,448
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

P: 4
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

Expert 10K+
P: 11,448
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

P: 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

Expert 10K+
P: 11,448
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

P: 4
[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.