Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the selected item in JList to and use casting

 
Dan Quartz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a part of my program, I have a JList that it has a list on locations, and I got an API that it should use an item from the JList and print out the weather of that location. So now I can not do it, because I use




but there is an error: Type mismatch: cannot convert from int to WeatherAPI.

This is the example of the API that works:


So I dont want to get the first option, i want to get the selected location by the user. It's all about casting. I also tried this which did not work:



I got the rest of the code, that it uses the "firstMatch, but it only uses it when its type is WeatherAPI. Also I got a bit of help from someone who has already done this program. Here is what he mentioned: Do you have a list of stations somewhere which you use to put information into your locList? If you do, when a user clicks something in the JList, you can use locList.getSelectedIndex() as the parameter for a stations.get call and the answer you get can be placed inside chosen.


So Do you have any idea?


Thank in advance.
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the point of this question?

You posted this question and got an answer 2 hours earlier:

http://stackoverflow.com/questions/15723134/how-to-get-the-selected-item-in-jlist-to-and-use-casting

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic