我正在尝试为更多请求编写通用asyncTask
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()上返回错误... 未经检查的调用 setClass(Class)作为原始类型RequestFactory.AsyncTaskInner的成员 取消选中&#39;执行(Params)&#39; 作为行类型&#39; android.os.AsyncTask&#39;
的成员答案 0 :(得分:0)
感谢。我应该写那个 RequestFactory.AsyncTaskInner&LT;的 TimeResponce 强>&GT; timeRequest;
timeRequest = new RequestFactory().new AsyncTaskInner<>();
timeRequest.setClass(TimeResponce.class);
timeRequest.execute();