0
我試着去寫更多的請求到setClass選中調用(類<T>)作爲原始類型的成員
public class AsyncTaskInner <T> extends AsyncTask<Void, Void, List<T>> {
Class<T> mClazz;
public void setDataListener(TimeDataListener dataListener) {
mDataListener = dataListener;
}
public void setClass(Class<T> clazz){
mClazz = clazz;
}
@Override
protected final List<T> doInBackground(Void... voids) {
String path = "";
final String requestItem = Config.getTime();
List<T> priceResponseList = null;
path = Config.getPath();
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
final int statusCode = connection.getResponseCode();
if (statusCode == 200) { // 200 -> STATUS_OK.
InputStream inputStream = new BufferedInputStream(connection.getInputStream());
String response = IOUtils.toString(inputStream, "UTF-8");
priceResponseList = getTimeResponse(response, mClazz);
}
} catch (NullPointerException | IOException e) {
e.printStackTrace();
}
return priceResponseList;
}
@Override
protected void onPostExecute(List<T> priceResponceList) {
super.onPostExecute(priceResponceList);
if (priceResponceList != null) {
mDataListener.onTimeDataReceived(priceResponceList);
}
}
}
它返回的setClass()方法錯誤和.execute通用的AsyncTask () ... 未經檢查調用setClass(類)作爲原料類型RequestFactory.AsyncTaskInner 到未選中呼叫「執行(PARAMS)」作爲行類型的成員「android.os.AsyncTask的成員'
可能重複http://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it – Radiodef
能否請您提供創建代碼調用這個異步任務? – GPuschka