未选中对List <t>的调用

时间:2015-11-17 14:06:24

标签: java android

Android Studio会显示此警告:

  

未选中调用List作为原始类型'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;
}

1 个答案:

答案 0 :(得分:2)

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

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

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