• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
reply
    Bookmark Topic Watch Topic
  • New Topic