Weather app (JSON) data is not showing in the textview
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I finished my weather app on android studio in Java and XML but when I run the app the data isn't showing. I'm using open weather for my JSON data and I already gave the permissions in the XML manifesto to access location and internet. I am only testing the code with 3 variables
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
I need to have those results from the JSON appear in my app somehow.
below is the main activity (weatherapp).
public class Weatherapp extends AppCompatActivity {
static TextView ctemp;
static TextView ftemp;
static TextView ktemp;
static TextView location;
static TextView pressure;
static TextView humidity;
static TextView mintempc;
static TextView mintempf;
static TextView mintempk;
static TextView maxtempc;
static TextView maxtempf;
static TextView maxtempk;
static TextView sealevel;
static TextView groundlevel;
static TextView windspeed;
static Button refresh;
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weatherapp);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Dowlode task = new Dowlode();
String provider = locationManager.getBestProvider(new Criteria(), false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String permissions,
// int grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
Location locationn = locationManager.getLastKnownLocation(provider);
Double lat = locationn.getLatitude();
Double lng = locationn.getLongitude();
task.execute("https://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=4ba583d5302c8723764443f9d6f08116");
ctemp = findViewById(R.id.ctemp);
ftemp = findViewById(R.id.ftemp);
ktemp = findViewById(R.id.ktemp);
location = findViewById(R.id.location);
pressure = findViewById(R.id.pressure);
humidity = findViewById(R.id.humidity);
mintempc = findViewById(R.id.mintempc);
mintempf = findViewById(R.id.mintempf);
mintempk = findViewById(R.id.mintempk);
maxtempc = findViewById(R.id.maxtempc);
maxtempf = findViewById(R.id.maxtempf);
maxtempk = findViewById(R.id.maxtempk);
sealevel = findViewById(R.id.sealevel);
groundlevel = findViewById(R.id.groundlevel);
windspeed = findViewById(R.id.windspeed);
refresh = findViewById(R.id.refresh);
below is my download activity code
public class Dowlode extends AsyncTask<String,Void,String >
@Override
protected String doInBackground(String... urls)
String result="";
URL url;
HttpURLConnection urlConnection =null;
try
url=new URL(urls[0]);
urlConnection=(HttpURLConnection) url.openConnection();
InputStream in =urlConnection.getInputStream() ;
InputStreamReader reader=new InputStreamReader(in);
int data = reader.read();
while (data!=-1)
char current = (char) data;
result += current;
data = reader.read();
return result;
catch (MalformedURLException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
try
JSONObject jsonObject = new JSONObject();
JSONObject weather = new JSONObject(jsonObject.getString("main"));
double tempreture = Double.parseDouble(weather.getString("temp"));
int ctempreture = (int) (tempreture- 273.15 );
int ftempreture = (int) (tempreture * 1.8-459.67);
int ktempreture = (int) (tempreture);
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
String location = jsonObject.getString("name");
double pressure = Double.parseDouble(weather.getString("pressure"));
String pressuree = pressure+ "pascal";
double humidity = Double.parseDouble(weather.getString("humidity"));
String humidityy= humidity+"";
double temp_min = Double.parseDouble(weather.getString("temp_min"));
int cmintemp = (int) (temp_min- 273.15 );
int fmintemp = (int) (temp_min * 1.8-459.67);
int kmintemp = (int) (temp_min);
double temp_max = Double.parseDouble((weather.getString("temp_max")));
int cmaxtemp = (int) (temp_max- 273.15 );
int fmaxtemp = (int) (temp_max * 1.8-459.67);
int kmaxtemp = (int) (temp_max);
double sea_level = Double.parseDouble(weather.getString("sea_level"));
int sealevel = (int) (sea_level);
double grnd_level = Double.parseDouble((weather.getString("grnd_level")));
int groundlevel= (int) (grnd_level);
JSONObject wind = new JSONObject(jsonObject.getString("wind"));
double speed = Double.parseDouble((wind.getString("speed")));
int speedd = (int) (speed);
catch (Exception e)
e.printStackTrace();
java android json xml android-studio
add a comment |
I finished my weather app on android studio in Java and XML but when I run the app the data isn't showing. I'm using open weather for my JSON data and I already gave the permissions in the XML manifesto to access location and internet. I am only testing the code with 3 variables
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
I need to have those results from the JSON appear in my app somehow.
below is the main activity (weatherapp).
public class Weatherapp extends AppCompatActivity {
static TextView ctemp;
static TextView ftemp;
static TextView ktemp;
static TextView location;
static TextView pressure;
static TextView humidity;
static TextView mintempc;
static TextView mintempf;
static TextView mintempk;
static TextView maxtempc;
static TextView maxtempf;
static TextView maxtempk;
static TextView sealevel;
static TextView groundlevel;
static TextView windspeed;
static Button refresh;
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weatherapp);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Dowlode task = new Dowlode();
String provider = locationManager.getBestProvider(new Criteria(), false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String permissions,
// int grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
Location locationn = locationManager.getLastKnownLocation(provider);
Double lat = locationn.getLatitude();
Double lng = locationn.getLongitude();
task.execute("https://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=4ba583d5302c8723764443f9d6f08116");
ctemp = findViewById(R.id.ctemp);
ftemp = findViewById(R.id.ftemp);
ktemp = findViewById(R.id.ktemp);
location = findViewById(R.id.location);
pressure = findViewById(R.id.pressure);
humidity = findViewById(R.id.humidity);
mintempc = findViewById(R.id.mintempc);
mintempf = findViewById(R.id.mintempf);
mintempk = findViewById(R.id.mintempk);
maxtempc = findViewById(R.id.maxtempc);
maxtempf = findViewById(R.id.maxtempf);
maxtempk = findViewById(R.id.maxtempk);
sealevel = findViewById(R.id.sealevel);
groundlevel = findViewById(R.id.groundlevel);
windspeed = findViewById(R.id.windspeed);
refresh = findViewById(R.id.refresh);
below is my download activity code
public class Dowlode extends AsyncTask<String,Void,String >
@Override
protected String doInBackground(String... urls)
String result="";
URL url;
HttpURLConnection urlConnection =null;
try
url=new URL(urls[0]);
urlConnection=(HttpURLConnection) url.openConnection();
InputStream in =urlConnection.getInputStream() ;
InputStreamReader reader=new InputStreamReader(in);
int data = reader.read();
while (data!=-1)
char current = (char) data;
result += current;
data = reader.read();
return result;
catch (MalformedURLException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
try
JSONObject jsonObject = new JSONObject();
JSONObject weather = new JSONObject(jsonObject.getString("main"));
double tempreture = Double.parseDouble(weather.getString("temp"));
int ctempreture = (int) (tempreture- 273.15 );
int ftempreture = (int) (tempreture * 1.8-459.67);
int ktempreture = (int) (tempreture);
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
String location = jsonObject.getString("name");
double pressure = Double.parseDouble(weather.getString("pressure"));
String pressuree = pressure+ "pascal";
double humidity = Double.parseDouble(weather.getString("humidity"));
String humidityy= humidity+"";
double temp_min = Double.parseDouble(weather.getString("temp_min"));
int cmintemp = (int) (temp_min- 273.15 );
int fmintemp = (int) (temp_min * 1.8-459.67);
int kmintemp = (int) (temp_min);
double temp_max = Double.parseDouble((weather.getString("temp_max")));
int cmaxtemp = (int) (temp_max- 273.15 );
int fmaxtemp = (int) (temp_max * 1.8-459.67);
int kmaxtemp = (int) (temp_max);
double sea_level = Double.parseDouble(weather.getString("sea_level"));
int sealevel = (int) (sea_level);
double grnd_level = Double.parseDouble((weather.getString("grnd_level")));
int groundlevel= (int) (grnd_level);
JSONObject wind = new JSONObject(jsonObject.getString("wind"));
double speed = Double.parseDouble((wind.getString("speed")));
int speedd = (int) (speed);
catch (Exception e)
e.printStackTrace();
java android json xml android-studio
have you tried debugging the app?
– Vladyslav Matviienko
Nov 16 '18 at 13:14
i have tried that but there doesnt seem to be any error
– TheLegandOf9gag
Nov 16 '18 at 13:24
add a comment |
I finished my weather app on android studio in Java and XML but when I run the app the data isn't showing. I'm using open weather for my JSON data and I already gave the permissions in the XML manifesto to access location and internet. I am only testing the code with 3 variables
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
I need to have those results from the JSON appear in my app somehow.
below is the main activity (weatherapp).
public class Weatherapp extends AppCompatActivity {
static TextView ctemp;
static TextView ftemp;
static TextView ktemp;
static TextView location;
static TextView pressure;
static TextView humidity;
static TextView mintempc;
static TextView mintempf;
static TextView mintempk;
static TextView maxtempc;
static TextView maxtempf;
static TextView maxtempk;
static TextView sealevel;
static TextView groundlevel;
static TextView windspeed;
static Button refresh;
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weatherapp);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Dowlode task = new Dowlode();
String provider = locationManager.getBestProvider(new Criteria(), false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String permissions,
// int grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
Location locationn = locationManager.getLastKnownLocation(provider);
Double lat = locationn.getLatitude();
Double lng = locationn.getLongitude();
task.execute("https://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=4ba583d5302c8723764443f9d6f08116");
ctemp = findViewById(R.id.ctemp);
ftemp = findViewById(R.id.ftemp);
ktemp = findViewById(R.id.ktemp);
location = findViewById(R.id.location);
pressure = findViewById(R.id.pressure);
humidity = findViewById(R.id.humidity);
mintempc = findViewById(R.id.mintempc);
mintempf = findViewById(R.id.mintempf);
mintempk = findViewById(R.id.mintempk);
maxtempc = findViewById(R.id.maxtempc);
maxtempf = findViewById(R.id.maxtempf);
maxtempk = findViewById(R.id.maxtempk);
sealevel = findViewById(R.id.sealevel);
groundlevel = findViewById(R.id.groundlevel);
windspeed = findViewById(R.id.windspeed);
refresh = findViewById(R.id.refresh);
below is my download activity code
public class Dowlode extends AsyncTask<String,Void,String >
@Override
protected String doInBackground(String... urls)
String result="";
URL url;
HttpURLConnection urlConnection =null;
try
url=new URL(urls[0]);
urlConnection=(HttpURLConnection) url.openConnection();
InputStream in =urlConnection.getInputStream() ;
InputStreamReader reader=new InputStreamReader(in);
int data = reader.read();
while (data!=-1)
char current = (char) data;
result += current;
data = reader.read();
return result;
catch (MalformedURLException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
try
JSONObject jsonObject = new JSONObject();
JSONObject weather = new JSONObject(jsonObject.getString("main"));
double tempreture = Double.parseDouble(weather.getString("temp"));
int ctempreture = (int) (tempreture- 273.15 );
int ftempreture = (int) (tempreture * 1.8-459.67);
int ktempreture = (int) (tempreture);
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
String location = jsonObject.getString("name");
double pressure = Double.parseDouble(weather.getString("pressure"));
String pressuree = pressure+ "pascal";
double humidity = Double.parseDouble(weather.getString("humidity"));
String humidityy= humidity+"";
double temp_min = Double.parseDouble(weather.getString("temp_min"));
int cmintemp = (int) (temp_min- 273.15 );
int fmintemp = (int) (temp_min * 1.8-459.67);
int kmintemp = (int) (temp_min);
double temp_max = Double.parseDouble((weather.getString("temp_max")));
int cmaxtemp = (int) (temp_max- 273.15 );
int fmaxtemp = (int) (temp_max * 1.8-459.67);
int kmaxtemp = (int) (temp_max);
double sea_level = Double.parseDouble(weather.getString("sea_level"));
int sealevel = (int) (sea_level);
double grnd_level = Double.parseDouble((weather.getString("grnd_level")));
int groundlevel= (int) (grnd_level);
JSONObject wind = new JSONObject(jsonObject.getString("wind"));
double speed = Double.parseDouble((wind.getString("speed")));
int speedd = (int) (speed);
catch (Exception e)
e.printStackTrace();
java android json xml android-studio
I finished my weather app on android studio in Java and XML but when I run the app the data isn't showing. I'm using open weather for my JSON data and I already gave the permissions in the XML manifesto to access location and internet. I am only testing the code with 3 variables
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
I need to have those results from the JSON appear in my app somehow.
below is the main activity (weatherapp).
public class Weatherapp extends AppCompatActivity {
static TextView ctemp;
static TextView ftemp;
static TextView ktemp;
static TextView location;
static TextView pressure;
static TextView humidity;
static TextView mintempc;
static TextView mintempf;
static TextView mintempk;
static TextView maxtempc;
static TextView maxtempf;
static TextView maxtempk;
static TextView sealevel;
static TextView groundlevel;
static TextView windspeed;
static Button refresh;
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weatherapp);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Dowlode task = new Dowlode();
String provider = locationManager.getBestProvider(new Criteria(), false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String permissions,
// int grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
Location locationn = locationManager.getLastKnownLocation(provider);
Double lat = locationn.getLatitude();
Double lng = locationn.getLongitude();
task.execute("https://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=4ba583d5302c8723764443f9d6f08116");
ctemp = findViewById(R.id.ctemp);
ftemp = findViewById(R.id.ftemp);
ktemp = findViewById(R.id.ktemp);
location = findViewById(R.id.location);
pressure = findViewById(R.id.pressure);
humidity = findViewById(R.id.humidity);
mintempc = findViewById(R.id.mintempc);
mintempf = findViewById(R.id.mintempf);
mintempk = findViewById(R.id.mintempk);
maxtempc = findViewById(R.id.maxtempc);
maxtempf = findViewById(R.id.maxtempf);
maxtempk = findViewById(R.id.maxtempk);
sealevel = findViewById(R.id.sealevel);
groundlevel = findViewById(R.id.groundlevel);
windspeed = findViewById(R.id.windspeed);
refresh = findViewById(R.id.refresh);
below is my download activity code
public class Dowlode extends AsyncTask<String,Void,String >
@Override
protected String doInBackground(String... urls)
String result="";
URL url;
HttpURLConnection urlConnection =null;
try
url=new URL(urls[0]);
urlConnection=(HttpURLConnection) url.openConnection();
InputStream in =urlConnection.getInputStream() ;
InputStreamReader reader=new InputStreamReader(in);
int data = reader.read();
while (data!=-1)
char current = (char) data;
result += current;
data = reader.read();
return result;
catch (MalformedURLException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
try
JSONObject jsonObject = new JSONObject();
JSONObject weather = new JSONObject(jsonObject.getString("main"));
double tempreture = Double.parseDouble(weather.getString("temp"));
int ctempreture = (int) (tempreture- 273.15 );
int ftempreture = (int) (tempreture * 1.8-459.67);
int ktempreture = (int) (tempreture);
Weatherapp.ctemp.setText(String.valueOf(ctempreture));
Weatherapp.ftemp.setText(String.valueOf(ftempreture));
Weatherapp.ktemp.setText(String.valueOf(ktempreture));
String location = jsonObject.getString("name");
double pressure = Double.parseDouble(weather.getString("pressure"));
String pressuree = pressure+ "pascal";
double humidity = Double.parseDouble(weather.getString("humidity"));
String humidityy= humidity+"";
double temp_min = Double.parseDouble(weather.getString("temp_min"));
int cmintemp = (int) (temp_min- 273.15 );
int fmintemp = (int) (temp_min * 1.8-459.67);
int kmintemp = (int) (temp_min);
double temp_max = Double.parseDouble((weather.getString("temp_max")));
int cmaxtemp = (int) (temp_max- 273.15 );
int fmaxtemp = (int) (temp_max * 1.8-459.67);
int kmaxtemp = (int) (temp_max);
double sea_level = Double.parseDouble(weather.getString("sea_level"));
int sealevel = (int) (sea_level);
double grnd_level = Double.parseDouble((weather.getString("grnd_level")));
int groundlevel= (int) (grnd_level);
JSONObject wind = new JSONObject(jsonObject.getString("wind"));
double speed = Double.parseDouble((wind.getString("speed")));
int speedd = (int) (speed);
catch (Exception e)
e.printStackTrace();
java android json xml android-studio
java android json xml android-studio
edited Nov 16 '18 at 13:49
Karishma Patel
11010
11010
asked Nov 16 '18 at 12:37
TheLegandOf9gagTheLegandOf9gag
216
216
have you tried debugging the app?
– Vladyslav Matviienko
Nov 16 '18 at 13:14
i have tried that but there doesnt seem to be any error
– TheLegandOf9gag
Nov 16 '18 at 13:24
add a comment |
have you tried debugging the app?
– Vladyslav Matviienko
Nov 16 '18 at 13:14
i have tried that but there doesnt seem to be any error
– TheLegandOf9gag
Nov 16 '18 at 13:24
have you tried debugging the app?
– Vladyslav Matviienko
Nov 16 '18 at 13:14
have you tried debugging the app?
– Vladyslav Matviienko
Nov 16 '18 at 13:14
i have tried that but there doesnt seem to be any error
– TheLegandOf9gag
Nov 16 '18 at 13:24
i have tried that but there doesnt seem to be any error
– TheLegandOf9gag
Nov 16 '18 at 13:24
add a comment |
1 Answer
1
active
oldest
votes
You are performing your async task before you do the findViewById stuff, so when you try to set the texts in the onPostExecute() method, the variables for the textviews are probably not set yet.
Also, you should better not use static variables in your activity. To avoid this, you can either put the Dowlode class inside your activity class, or you can pass the activity (or the relevant views) to the Dowlode class via a constructor.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338062%2fweather-app-json-data-is-not-showing-in-the-textview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are performing your async task before you do the findViewById stuff, so when you try to set the texts in the onPostExecute() method, the variables for the textviews are probably not set yet.
Also, you should better not use static variables in your activity. To avoid this, you can either put the Dowlode class inside your activity class, or you can pass the activity (or the relevant views) to the Dowlode class via a constructor.
add a comment |
You are performing your async task before you do the findViewById stuff, so when you try to set the texts in the onPostExecute() method, the variables for the textviews are probably not set yet.
Also, you should better not use static variables in your activity. To avoid this, you can either put the Dowlode class inside your activity class, or you can pass the activity (or the relevant views) to the Dowlode class via a constructor.
add a comment |
You are performing your async task before you do the findViewById stuff, so when you try to set the texts in the onPostExecute() method, the variables for the textviews are probably not set yet.
Also, you should better not use static variables in your activity. To avoid this, you can either put the Dowlode class inside your activity class, or you can pass the activity (or the relevant views) to the Dowlode class via a constructor.
You are performing your async task before you do the findViewById stuff, so when you try to set the texts in the onPostExecute() method, the variables for the textviews are probably not set yet.
Also, you should better not use static variables in your activity. To avoid this, you can either put the Dowlode class inside your activity class, or you can pass the activity (or the relevant views) to the Dowlode class via a constructor.
answered Nov 16 '18 at 14:04
RidcullyRidcully
18.8k75471
18.8k75471
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338062%2fweather-app-json-data-is-not-showing-in-the-textview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
have you tried debugging the app?
– Vladyslav Matviienko
Nov 16 '18 at 13:14
i have tried that but there doesnt seem to be any error
– TheLegandOf9gag
Nov 16 '18 at 13:24