Aplikacja ma w tle pobierać zawartość strony a następnie wklejać to do adresu i pobierać JSONa. Dlaczego w onPostExecute wywala mi błąd?
public class downloadJSON extends AsyncTask<Void,Void,Boolean>{
@Override
protected Boolean doInBackground(Void... strings) {
String sURL = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"; //just a string
try {
String json = Jsoup.connect(sURL).ignoreContentType(true).execute().body();
json=json.replace("[","");
jsonData=json.split(",");
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean success){
if (success){
try {
Log.i("Json0", jsonData[0]);
URL url = new URL("https://hacker-news.firebaseio.com/v0/item/" + jsonData[0] + ".json?print=pretty");
URLConnection request = url.openConnection();
request.connect();
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
JsonObject rootobj = root.getAsJsonObject();
String title = rootobj.get("title").getAsString(); //just grab the zipcode
Log.i("tittle", title);
}catch (Exception e){
e.printStackTrace();
}
}