Jump to content
Excelsior Forums
Sign in to follow this  
ATBEST

StringIndexOutOfBoundsException : -1

Recommended Posts

trying to build and package very large java program.

runs fine as standalone application, as soon as i try it with JET i get StringIndexOutOfBoundsException : -1 errors which is odd..

Explanation of Code:

User types into a text field.. code enables user to use shortcuts, like to enter 1000 user just types 'T' and the smarttextfield  converts that to 1000..

this works fine .. but not when built using jet.

piece of code is below!

if ( evt.getSource() == mQuantityField ) {

int quantity = 0;

String quantityText = mQuantityField.getText();

if ( !isNumeric( evt.getKeyChar() ) ) {

if(isAlpha(evt.getKeyChar())){

  String stringQuantity = quantityText.substring( 0, quantityText.lastIndexOf( evt.getKeyChar() ) );

if ( evt.getKeyChar() == 'h' || evt.getKeyChar() == 'H' ) {

if ( stringQuantity.length() == 0 ) {

stringQuantity = "1";

}

quantity = Integer.parseInt( stringQuantity ) * 100;

quantityText = String.valueOf( quantity );

} else {

if ( evt.getKeyChar() == 't' || evt.getKeyChar() == 'T' ) {

if ( stringQuantity.length() == 0 ) {

stringQuantity = "1";

}

quantity = Integer.parseInt( stringQuantity ) * 1000;

quantityText = String.valueOf( quantity );

} else {

quantityText = stringQuantity;

}

}

}

mInputValues.setQuantity( quantityText ); // Remember the new quantity value

mInputValues.fireEvent(); // Tell anyone who cares we have changed something

} else {

mInputValues.setQuantity( quantityText ); // Remember the new quantity value

mInputValues.fireEvent( this ); // Tell anyone who cares we have changed something

}

}

Share this post


Link to post
Share on other sites

We have received your defect report via e-mail. Thanks for doubling it in the forum.  B)

We are looking into this issue and we will be back to you with our resolution soon.

Share this post


Link to post
Share on other sites

The piece of code you sent is not sufficient to reveal the problem. For instance, the following small sample works fine both with Sun JVM and Excelsior JET:

-------------------------- TFtest.java ---------------

import javax.swing.*;   

import java.awt.*;

import java.awt.event.*;

public class TFtest {

    public static void main(String[] args) {

        JFrame frame = new JFrame("Text Field Test");

        frame.setSize (50, 50);

        final JTextField tf = new JTextField();

        tf.addKeyListener(new KeyAdapter(){

            public void keyReleased(KeyEvent evt){

              String quantityText = tf.getText();

              if ( !Character.isDigit( evt.getKeyChar() ) ) {

                if(Character.isLetter(evt.getKeyChar())){                             

                    String stringQuantity = quantityText.substring( 0, quantityText.lastIndexOf( evt.getKeyChar() ) );

                }

              }

            }

        });

        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {

                System.exit(0);

            }

        });

        frame.getContentPane().add(tf);

        frame.setVisible(true);

    }

}

----------------------------------------

So, we need a complete sample to reproduce the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×