473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 32032
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

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

Similar topics

0
by: Phillip Montgomery | last post by:
Hello all; I'm trying to debug an issue with a java script called, SelectSockets. It appears to be a fairly common one found on the web. I downloaded the SGI Java v1.4.1 installation from SGI's...
12
by: sandyw | last post by:
Exception in thread "main" java.lang.NullPointerException at company.Employee.inputEmployee(Employee.java:172) at company.Employee.main(Employee.java:267) which I got before... Can someone please...
6
by: Light | last post by:
Hi I m getting this error while i m trying to run my program and i don't understand why that happens. import java.util.*; public class Exercise6 {
3
by: Ananthu | last post by:
Hi This is my codings in order to access mysql database from java. Codings: import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;
9
by: tiyaramunna | last post by:
I am trying to configure my system with Java program just to practice on the coding....when i compile a test.java program i am able to see the class file but i cant run the program ... I am getting...
4
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp...
2
by: lilyumestar | last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours Error Message ...
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.