当我尝试实现onPostExecute方法时,它给我一个错误,删除@Override并且需要调用超类或方法。但是,我确实称之为超类等。这是我的Asynctask代码。
public class parsenfill extends AsyncTask<Void,Void,Void> {
@Override
protected Void doInBackground(Void... params) {
try {
JsonParsing parse = new JsonParsing(url);
parse.parseFile(3, urls);
return null;
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void...voids ) {
super.onPostExecute(voids);
//Body of method
}
}
答案 0 :(得分:1)
从方法签名中删除...
。 onPostExecute
的参数类型是doInBackground()
的返回类型,即您的案例中仅为Void
。
答案 1 :(得分:1)
试试这个
private class MyAsyncClass extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
/**
* invoked on the UI thread before the task is executed. This step
* is normally used to setup the task, for instance by showing a
* progress bar in the user interface.
*/
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
/**
* Invoked on the background thread immediately after onPreExecute()
* finishes executing. This step is used to perform background
* computation that can take a long time. The parameters of the
* asynchronous task are passed to this step.
*/
return null;
}
@Override
protected void onPostExecute(Void result) {
/**
* Invoked on the UI thread after the background computation
* finishes. The result of the background computation is passed to
* this step as a parameter.
*/
super.onPostExecute(result);
}
}
然后你必须在这样的UI线程上调用这个 async class 。
new MyAsyncClass().execute();
答案 2 :(得分:0)
@Override
protected void onPostExecute(Void...voids ) {
super.onPostExecute(voids);
//Body of method
}
因为...代表字符串数组,你的背景返回无效。
@Override
protected void onPostExecute(Void voids ) {
super.onPostExecute(voids);
//Body of method
}