| Author |
JList problem
|
axel axek
Greenhorn
Joined: May 28, 2009
Posts: 20
|
|
|
I am having problems reading from a JList, my application consists in adding text line by line from a text file to a JList, ..and the problem that i am facing is...how can i read elements from Jlist, character by character .... help please....
|
 |
axel axek
Greenhorn
Joined: May 28, 2009
Posts: 20
|
|
this is the code that reads form txt:
where "model" is Jlist model
and i have tried to read from list:
the line i'm tryng to read is something like: "S LLLL 0.2"
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1808
|
|
Because you are trying to access a character in the string that doesn't exist. I don't know the format of your data, but maybe you have a blank line.
In any case you should be using the String.length() method to control the looping.
|
 |
James Dixon
Ranch Hand
Joined: Jun 20, 2009
Posts: 32
|
|
I have to say it is a bit difficult to follow your code as it doesn't seem to be complete (for instance where do the for loops for k and j finish?).
But looking at the code as it stands and at the error message it is basically saying that you are trying to reference a part of the string ('s1') that does not exist. You should be able to see this if you output the length of the string 's1' and the value of k where it fails (you'll probably find that k >= s1.length()).
<hint>Remember that String.charAt(int) references the string as it would a list so characters are retreived from position 0 rather than 1.</hint>
Also not sure if you have been asked to use for loops for your project but if not you may want to have a look in using StringTokenizer, this should take a lot of the pain out of what you are trying to do.
Have fun...
|
 |
 |
|
|
subject: JList problem
|
|
|