Looping AsyncTask Class must either be declared abstract or implement abstract method(循环 AsyncTask 类必须声明为抽象或实现抽象方法)
问题描述
我正在尝试遍历表中的一些记录,并为每条记录使用一个值作为参数;
I am trying to loop through some records in my table and for each record, use a value as a parameter to;
- 获取一个网页来解析一些 html
- 获取一些要解析的 JSON 数据并从中获取几个值
这些都可以自己完美地工作,但我无法让它们都在 AsyncTask 中工作.我这里有代码.我知道我可能离题很远,但如果有人能告诉我我的想法是怎样的,我会非常感激.
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.
第一行
private class FetchWebsiteData extends AsyncTask<Void, String, Void> {
我明白了
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 += "
--------
";
str += "names: "+articles3.getJSONObject(0).getString("MasternodeIP");
str += "
--------
";
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();
}
}
推荐答案
改变这个
protected String doInBackground(String urls3, String result3)
到
protected String doInBackground(String... args)
然后在 doInBackground 函数中像这样声明变量
Then declare your variables like so inside your doInBackground function
String urls3 = args[0];
String result3 = args[1];
您还需要将 onPostExecute 更正为
You will also need to correct your onPostExecute to
protected void onPostExecute(String result)
和你的类声明
private class FetchWebsiteData extends AsyncTask<String, Void, String>
这篇关于循环 AsyncTask 类必须声明为抽象或实现抽象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:循环 AsyncTask 类必须声明为抽象或实现抽象方法
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01