posted 10 years ago
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.