Background: I have a Picasso Statement in my java file, which reads a JSON and then formats that data to the screen. The Issue: Once my JSON has been read, Picasso does not load Image from a URL to the ImageView, instead, it stops all statements after that from occurring, such as setting the text in a TextView
The JSON I am reading:
{
"coord":{
"lon":139.01,
"lat":35.02
},
"weather":[
{
"id":800,
"main":"Clear",
"description":"clear sky",
"icon":"01n"
}
],
"base":"stations",
"main":{
"temp":285.514,
"pressure":1013.75,
"humidity":100,
"temp_min":285.514,
"temp_max":285.514,
"sea_level":1023.22,
"grnd_level":1013.75
},
"wind":{
"speed":5.52,
"deg":311
},
"clouds":{
"all":0
},
"dt":1485792967,
"sys":{
"message":0.0025,
"country":"JP",
"sunrise":1485726240,
"sunset":1485763863
},
"id":1907296,
"name":"Tawarano",
"cod":200
}
I can retrieve the data and print that data to a TextView with no problems at all and all works fine. The code below is how I am retrieving the data:
JSONObject jo = new JSONObject(data);
JSONObject main_object = jo.getJSONObject("main");
JSONArray array = jo.getJSONArray("weather");
JSONObject object = array.getJSONObject(0);
String icon = object.getString("icon");
String temp = String.valueOf(main_object.getDouble("temp"));
String description = object.getString("description");
String city = jo.getString("name");
So when formatting temp, description and city, I have no problems. NOTE: I am using a Fragment in my Activity and a file to fetch the data, which then formats the text view etc in the fragment as follows:
Tab1Fragment.txtCelcius.setText(temp);
The Issue arises when I use Picasso to try and obtain the "icon" value in he JSON, so "01n". I simply cannot get the image loading in and not only that, but all other processes then terminate?
For example:
Tab1Fragment.txtCelcius.setText(temp);
Picasso.get().load("http://openweathermap.org/img/w/01d.png").into(Tab1Fragment.weatherIcon);
Tab1Fragment.txtCity.setText(city);
"temp" will be set to the text of txtCelcius, but Picasso will not load the URL and set the imageview AND the "name" statement will also not run, it will however, if I comment the Picasso line.
I use
String iconUrl = "http://openweathermap.org/img/w/"+icon+".png";
Then
Picasso.get().load(iconUrl).into(Tab1Fragment.weatherIcon);
As I have read that is the best way of achieveing my task, but something isn't working and I can't see what exactly? My Picasso syntax I see is fine, and I do not see any errors in logcat etc..
All help is appreciated.
Edit: Tab1Fragment Code with ImageView declared
weatherIcon = (ImageView) rootView.findViewById(R.id.imageView);