473,770 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"main" java.lang.Strin gIndexOutOfBoun dsException: String index out of range: -2

4 New Member
Hello,

I have a question about this error:

Exception in thread "main" java.lang.Strin gIndexOutOfBoun dsException: 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\C loudscape_10.1
SET TRANSLATION=C:\ Translation
set CLASSPATH=%DERB Y_INSTALL%\lib\ derby.jar;%DERB Y_INSTALL%\lib\ derbytools.jar; %TRANSLATION%\l ib\Translation. jar;

echo %CLASSPATH%

C:\Translation\ jdk\jre\bin\jav a -classpath %CLASSPATH%;C:\ Translation\Con versions src.utilities.D ataConversionUt ilityDaily

pause

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

I have a question about this error:

Exception in thread "main" java.lang.Strin gIndexOutOfBoun dsException: 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
nrperry
4 New Member
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.ap pend(text.delet eCharAt(text.le ngth()-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 Recognized Expert MVP
Hi, I looked at line that the errors is on. Here is the code that is erroring:

sqlStatement.ap pend(text.delet eCharAt(text.le ngth()-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.prin tln()
method calls at certain positions you don't trust. btw, what's the type of 'text'?

kind regards,

Jos
Aug 3 '07 #4
nrperry
4 New Member
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.prin tln()
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 Recognized Expert MVP
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
nrperry
4 New Member
[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
3010
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 webpage and installed it using SGI's swmgr application. The installation was very straight forward and there were no errors when I installed the package. Then I ran /usr/java2/bin/javac SelectSockets.java to make the SelectSockets.class file.
12
6682
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 help me. This is where the error occures line 172 for (Employee_listing e : employees) { String emp = e.getEmpId(); line 267
6
24256
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
6444
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
3285
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 the following error Exception in thread "main" java.lang.NoClassDefFoundError: test Caused by: java.lang.ClassNotFoundException: test at java.net.URLClassLoader$1.run(Unknown Source) at...
4
14730
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 "appframework-1.0.3.jar;swing-worker-1.1.jar";CurrentStrobe.jar com.visionpro.currentstrobe.CurrentStrobeApp However, the statement below produces the error: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar" -jar CurrentStrobe.jar Exception in thread "main"...
2
3961
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 "Main" Java.lang NullPointerException at Project1.sortingByZipCode<Project1.java:80> at Project1.main<Project1.java:31> Here is the Source Code
3
7659
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 sortmergejoin.MergeJoin.Field(MergeJoin.java:204) at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84) at sortmergejoin.MergeJoin.<init>(MergeJoin.java:34) at sortmergejoin.Main.main(Main.java:24) Java Result: 1"
1
6757
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 "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1041) at java.awt.Container.add(Container.java:365) at orderingsystem.OrderingSystem.<init>(OrderingSystem.java:261) at...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.