Problem with '/n'

hello all,

was writing a code given below

strtext=textField.getText();

for(i=0;i<strtext.length();i++)

{

code=strtext.charAt(i);

if(!(((code>=2309)&&(code<=2399)) ||(code == 32) ||(code =='\n')) )

{

new MessageDialog(window,"error messg");

return;

}

}

let me explain the code a bit:

textfield is a Text Field widget and textfeild.getText() will return the text entered and is saved in a string strtext. All the variables are initialized appropriately. Also MessageDialog is another widget container which will be displayed if the conditions are met.The code works fine if I exclude one condition,i.e.,code == '\n' (escape sequence for line feed). I just included this condition.

Now whenever I include a line feed in the textfield(or strtext for that matter) the following error cames up

(java.lang.ArrayIndexOutOfBoundsException

at java.lang.reflect.Array.get(Native Method)

Most of this code uses the Buoy widget library(an open source library built on top of Swing) and is written in Beanshell Script( another Java OS scripting language), so it could also be an error related to the scripting language(though I don't think it is, but you can never be sure)

Help needed plz....

[1613 byte] By [KsRa] at [2007-11-26 16:04:33]
# 1

KR,

"\n" is not '\n'

If its a local file try [url=http://mindprod.com/jgloss/eol.html]String eol = System.getProperty("line.separator");[/url]

If it's not local I suggest you test for chars 13, 10, and 13-10... (and maybe even 10-13 just in case some other halfwit gets creative.)

Keith.

corlettka at 2007-7-8 22:26:31 > top of Java-index,Java Essentials,New To Java...
# 2
I'm confused. If you are using String#charAt(int), a char is returned. How could the value ever be 2309 or 2399? In terms of determining an end of line, take a look at java.util.Scanner.nextLine().- Saish
Saisha at 2007-7-8 22:26:31 > top of Java-index,Java Essentials,New To Java...