我已經建立了以下簡單的AsyncTask:簡單的AsyncTask沒有工作,我拋出錯誤
package com.example.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.os.AsyncTask;
public class HelloWorldActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
private class SimpleTask extends AsyncTask<Void, Void, Void> {
@Override
protected void doInBackground(Void... res) {}
}
}
但它給我的錯誤:
[javac] /home/gizkp/happ/src/com/example/helloworld/HelloWorldActivity.java:17: error: HelloWorldActivity.SimpleTask is not abstract and does not override abstract method doInBackground(String...) in AsyncTask
[javac] private class SimpleTask extends AsyncTask<String, String, String> {
[javac] ^
[javac] /home/gizko/happ/src/com/example/helloworld/HelloWorldActivity.java:20: error: doInBackground(String...) in HelloWorldActivity.SimpleTask cannot override doInBackground(Params...) in AsyncTask
[javac] protected void doInBackground(String... res) {}
[javac] ^
[javac] return type void is not compatible with String
[javac] where Params,Result are type-variables:
[javac] Params extends Object declared in class AsyncTask
[javac] Result extends Object declared in class AsyncTask
[javac] /home/gizko/happ/src/com/example/helloworld/HelloWorldActivity.java:19: error: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] 3 errors
我不明白的是與腳麻這樣一個簡單的代碼。我也嘗試過改變Asynctask參數而沒有任何成功。
它還挺作品,但仍然拋出錯誤對我。爲了在沒有編譯錯誤的情況下工作,我必須得到回報。 –
@gizko是當然,你可以返回null,它會工作,然後 –