hi sir i have seen the whole stack overflow but did not found aswer please help me i am getting json data from api and but i am not able to get few items from this i am getting this error many times. if there is any question or solution that i missed then please help me to solve please..
private class JsonTask extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(MainActivity.this);
pd.setMessage("Please wait");
pd.setCancelable(false);
pd.show();
}
protected String doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
Log.e(TAG, "doInBackground: BUFFER" + reader.read());
while ((line = reader.readLine()) != null) {
buffer.append(line + "\n");
Log.e(TAG, "> " + line); //here u ll get whole response...... :-)
Log.e(TAG, "doInBackground: length " + line);
}
return buffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(String result1) {
super.onPostExecute(result1);
String result = result1.toString();
if (pd.isShowing()) {
pd.dismiss();
}
Log.e(TAG, "onPostExecute: " + result);
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String name = jObject.getString("name");
Log.e(TAG, "onPostExecute: ");
} // End Loop
Log.e(TAG, "onPostExecute: jsion " + jArray.length());
} catch (JSONException e) {
Log.e(TAG, "onPostExecute Error: " + e.toString());
}
}
}
here is the calling function of that with api
new JsonTask().execute("https://api.iextrading.com/1.0/ref-data/symbols");