[but I am getting null pointer exception error][1]
My error in line protected class GetDataCountry extends AsyncTask<Void, Void, String> and my error in line List list=context.getElementsByTag("li"), I am using below code to get List Element from API: "https://www.fxexchangerate.com/currency-converter-rss-feed.html" by using jsoup I am fetching details but its throwing some exception.
protected class GetDataCountry extends AsyncTask<Void, Void, String> { // error in line
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Fetching conntry data");
progressDialog.setCancelable(false);
progressDialog.show();
}
@Override
protected String doInBackground(Void... voids) {
StringBuffer response = null;
try {
String path = "https://www.fxexchangerate.com/currency-converter-rss-feed.html";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
// Reading response from input Stream
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String output;
response = new StringBuffer();
while ((output = in.readLine()) != null) {
response.append(output);
}
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return response.toString();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if (progressDialog.isShowing())
progressDialog.dismiss();
Document document = Jsoup.parse(s);
Element context = document.getElementsByClass("rss").first();
List<Element> list=context.getElementsByTag("li"); //error in line
for (int i=0; i<list.size();i++)
{
String url=list.get(i).getElementsByTag("a").first().attr("href");
String currencyName=list.get(i).text();
listCountry.add(currencyName);
listCountryCode.put(currencyName,url);
}
}
}
[1]: https://i.stack.imgur.com/1uQou.png