gpt4 book ai didi

java - 未经检查的对 List 的调用

转载 作者:太空狗 更新时间:2023-10-29 13:16:47 24 4
gpt4 key购买 nike

Android Studio 显示此警告:

Unchecked call to List as a member of raw type 'ConnectionSuccess

如果我检查类型或什么,我该如何跳过这个警告?


请帮忙。

  public class RequestTask {
private Context mContext;
ConnectionSuccess connectionSuccess;
RequestHandler requestHandler;
ProgressDialog progressDialog;

public RequestTask(Context context, ConnectionSuccess connectionSuccess) {
this.mContext = context;
this.connectionSuccess = connectionSuccess;
progressDialog = new ProgressDialog(mContext);
progressDialog.setMessage(mContext.getResources().getString(R.string.loading));
}

// Request a string response
public void MakeRequest() {
String URL = mContext.getResources().getString(R.string.menu_url);
if (ConnectionTracker.isNetworkAvailable(mContext)) {
progressDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL,
new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create();
Response response1 = gson.fromJson(response, Response.class);
response1.setItemsList(response1.getItemsList());


//the warning shows here

connectionSuccess.onResponse(response1.getItemsList());

} catch (Exception e) {
e.printStackTrace();
}
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Error handling
progressDialog.dismiss();
Toast.makeText(mContext, mContext.getResources().getString(R.string.error_message), Toast.LENGTH_LONG).show();
error.printStackTrace();
}
});
// Add a request to RequestQueue.
MySingleton.getInstance(mContext).addToRequestQueue(stringRequest);
} else if (!ConnectionTracker.isNetworkAvailable(mContext)) {
Toast.makeText(mContext, mContext.getResources().getString(R.string.no_internet), Toast.LENGTH_LONG).show();
}
}
}

public class More extends Fragment implements ConnectionSuccess<Data> {
@Override
public void onResponse(List<Data> result) {
}
}

    public interface ConnectionSuccess<T> {
void onResponse(List<T> result);
}

public class Data {
@SerializedName("arabic_title")
String arabic_title;
@SerializedName("english_title")
String english_title;
@SerializedName("url")
String url;

public String getArabic_title() {
return arabic_title;
}

public void setArabic_title(String arabic_title) {
this.arabic_title = arabic_title;
}

public String getEnglish_title() {
return english_title;
}

public void setEnglish_title(String english_title) {
this.english_title = english_title;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}
}



@SerializedName("data")
List<Data> itemsList;

public List<Data> getItemsList() {
return itemsList;
}

public void setItemsList(List<Data> itemsList) {
this.itemsList = itemsList;
}

最佳答案

public interface ConnectionSuccess<T> {
void onResponse(List<T> result);
}

ConnectionSuccess有一个类型参数 T ,但在您的构造函数 arg 和字段声明中,您没有将类型参数传递给它。你可能意味着两者都是 ConnectionSuccess<Data>

这将允许编译器在您调用 connectionSuccess.onResponse(response1.getItemsList()) 时计算出它应该期望类型为 List<Data> 的参数

关于java - 未经检查的对 List<T> 的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com