Issue
I'm receiving value in JSON format by calling a simple select query.
I'm using AsyncTask
for that.
The problem is sometimes it's working fine but sometimes the response_value
is null without any change.
What should I do?
What am I missing?
CODE OF doInBackground(String... strings)
URL url = new URL(GetUrl.URL_MAIN_CATEGORIES_DATA);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String response_value = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
response_value += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return response_value;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Solution
Try logging the exception in your catch blocks instead of printing stack trace.
Log.e("Yourtag","Exception occurred",e);
You must be getting an exception but you can't see it with the stack trace on android. That's the only way that it can work sometimes and other times it won't.
Answered By - Kushan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.