Getting strings from a list
Hi, I got a JList and everytime I select an item on the list it performs an action. What I am trying to do is get the string of the list and display it on a text field, I am using the following code to do so:
public void valueChanged(ListSelectionEvent ev)
{
int nr;
nr = stationList.getSelectedIndex();
switch (nr)
{
case 0: String rv = stationList.getElementAt();
destinationField.setText(rv);
break;
}
}
It gives me the following error:
getElementAt(int) in javax.swing.DefaultListModel cannot be aplied to ()
Any idea on what I am doing wrong?
Thanks for your inputs
[667 byte] By [
Duskana] at [2007-10-3 6:02:32]

For the nth time, use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] when posting code so the code is readable.
Read the API. Figure out what parameters are required to invoke the getElementAt(...) method and then make sure you are using the correct parameters.
> case 0: String rv = stationList.getElementAt();
u r getting the element at which position? u should specify that..and y r u using a switch statement ? u dont need that...
the error itself states that the method has a param and that parameter is nothing but the index..
change it tostationList.getElementAt(nr);
> u r getting the element at which position? u should specify that..and y
> r u using a switch statement ? u dont need that... the error itself states
> that the method has a param and that parameter is nothing but the
> index.. change it to stationList.getElementAt(nr);
Please don't bother to responding until you get your keyboard fixed. Half of your typed words are missing letters. So nobody knows the heck you are trying to say.