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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nrperry
    New Member
    • Aug 2007
    • 4

    #1

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

    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?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by nrperry
    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

    Comment

    • nrperry
      New Member
      • Aug 2007
      • 4

      #3
      Originally posted by JosAH
      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.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by nrperry
        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

        Comment

        • nrperry
          New Member
          • Aug 2007
          • 4

          #5
          Originally posted by JosAH
          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?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by nrperry
            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

            Comment

            • nrperry
              New Member
              • Aug 2007
              • 4

              #7
              [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.

              Comment

              Working...