I am trying to loop through some records in my table and for each record, use a value as a parameter to;
- get a webpage to parse some html
- get some JSON data to parse and get a couple of values from
These both worked perfectly by themselves, but I can not get them both working in an AsyncTask. I have the code here. I know I am probably way off, but if someone could give me a nudge into how my thinking is off, I'd really appreciate it.
On the first line
private class FetchWebsiteData extends AsyncTask<Void, String, Void> {
I get
Class FetchWebsiteData must either be declared abstract or implement abstract method doInBackground(params...) in 'AsynTask'
As an error message and underlined in red.
private class FetchWebsiteData extends AsyncTask<Void, String, Void> { @Override protected void onPreExecute() { super.onPreExecute(); mProgressDialog = new ProgressDialog(summary.this); mProgressDialog.setMessage("Loading..."); mProgressDialog.setIndeterminate(false); mProgressDialog.show(); } protected String doInBackground(String urls3, String result3) { helper = new TaskDBHelper(summary.this); SQLiteDatabase sqlDB = helper.getReadableDatabase(); Cursor dataCount = sqlDB.rawQuery("select TASK from " + TaskContract.TABLE, null); ArrayList<String> temp = new ArrayList<String>(); dataCount.moveToFirst(); do { temp.add(dataCount.getString(0)); } while (dataCount.moveToNext()); dataCount.close(); StringBuilder sb = new StringBuilder(); for (String s : temp) { wallBal = s; //-------------------------------------------- try { Document document = Jsoup.connect(URL+wallBal).get(); Document doc = Jsoup.parse(document.text()); balance = new Double(doc.text()); helper = new TaskDBHelper(summary.this); SQLiteDatabase sqlDB2 = helper.getWritableDatabase(); String sql9 = String.format("UPDATE " + TaskContract.TABLE + " SET " + TaskContract.Columns.OLDBAL + " = " + TaskContract.TABLE + "." + TaskContract.Columns.BAL + " WHERE task='" + wallBal + "'"); sqlDB2.execSQL(sql9); String sql = String.format("UPDATE " + TaskContract.TABLE + " SET " + TaskContract.Columns.BAL + " = " + balance + " WHERE task='" + wallBal + "'"); sqlDB2.execSQL(sql); Cursor dataCount2 = sqlDB.rawQuery("select " + TaskContract.Columns.OLDBAL + " from " + TaskContract.TABLE + " WHERE " + TaskContract.Columns.TASK + " = '" + wallBal + "'", null); dataCount2.moveToFirst(); oldbalance = dataCount2.getDouble(0); if(balance != oldbalance) { make(); } mProgressDialog.dismiss(); JSONObject json3 = new JSONObject(result3); String str = ""; JSONArray articles3 = json3.getJSONArray("data"); str += "articles length = "+json3.getJSONArray("data").length(); str += "\n--------\n"; str += "names: "+articles3.getJSONObject(0).getString("MasternodeIP"); str += "\n--------\n"; MNIP = articles3.getJSONObject(0).getString("MasternodeIP"); Sts = articles3.getJSONObject(0).getString("ActiveCount"); helper = new TaskDBHelper(summary.this); SQLiteDatabase sqlDB22 = helper.getWritableDatabase(); String sql91 = String.format("UPDATE " + TaskContract.TABLE + " SET " + TaskContract.Columns.IP + " = '" + MNIP + "' WHERE task='" + task + "'"); sqlDB22.execSQL(sql91); String sql10 = String.format("UPDATE " + TaskContract.TABLE + " SET " + TaskContract.Columns.STATUS + " = '" + Sts + "' WHERE task='" + task + "'"); sqlDB22.execSQL(sql10); updateUI(); } catch (JSONException | IOException e) { e.printStackTrace(); } //----------------------------------------------------- } //-------------------------------------------------------------------- //return null; return GET(urls3); } protected void onPostExecute(Void result) { updateUI(); } }