• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList problem

 
axel axek
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic