Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question, String index out of range

Status
Not open for further replies.

magnus2

Programmer
Mar 8, 2004
23
SE
In an applet I got this error-message in a Java-s system window. What could be the problem? Grateful for comments.


java.lang.StringIndexOutOfBoundsException: String index out of range: -13

at java.lang.String.substring(Unknown Source)

at print.PrintDataSource.shortText(PrintDataSource.java:175)

at print.PrintDataSource.setData(PrintDataSource.java:143)

at print.PrintDataSource.(PrintDataSource.java:106)

at print.Print.(Print.java:117)

at gui.GUIInterface.startPrint(GUIInterface.java:359)

at gui.Entry.print(Entry.java:634)

at gui.Entry.okButtonPressed(Entry.java:693)

at gui.Entry.actionPerformed(Entry.java:918)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)


Kind regards /Magnus
 
You are using the 'substring' command somewhere. You are probably doing something like:

myString.substring(0, myString.indexOf("*"));

...or something like that and your string doesn't contain the (for example) asterisk, so you are effectively asking it for:

myString.substring(0, -1);

...which would lead to the out-of-bounds error.

Check it out. Post all your substring commands if this doesn't help.

Good luck.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top