【问题标题】:How to solve Unchecked call to 'GsonRequest(Params)' as a member of raw type?作为原始类型的成员,如何解决对“GsonRequest(Params)”的未经检查的调用?
【发布时间】:2016-11-30 09:06:25
【问题描述】:

我的编辑器收到警告。

作为原始类型的成员对“GsonRequest(int, String, Class, Map, Listener, ErrorListener)”的未经检查的调用 'com.inc.woppi.demoapp.GsonRequest'

GsonRequest 类复制自 Android Dev:https://developer.android.com/training/volley/request-custom.html

当我的电话在下面时:

// args: url, gson class, response listener, error listener
final GsonRequest gsonRequest = new GsonRequest(
        apiUrl,
        SeatRequestModel.class,
        null,
        new Response.Listener<SeatRequestModel>() {
            @Override
            public void onResponse(SeatRequestModel res) {

                try {
                    boolean errorFound = res.isError();

                    if(errorFound) {
                        //handle error
                    } else {

                        String seatId = res.getData().getSeatId();
                    }

                } catch (Exception e) {
                    Toast.makeText(activityContext, activityContext.getResources().getString(R.string.err_system_response_format_error), Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        //handle error
    }
}){
    @Override
    protected Map<String,String> getParams(){
        Map<String,String> params = new HashMap<String, String>();

        params.put("from", "australia");
        params.put("to", "canada");

        return params;
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String,String> params = new HashMap<String, String>();

        return params;
    }
};

// add the request to the RequestQueue.
VolleySingleton.getInstance(this.getApplicationContext()).addToRequestQueue(gsonRequest);

【问题讨论】:

  • final GsonRequest&lt;SeatRequestModel&gt; gsonRequest = new GsonRequest&lt;&gt;(
  • 不错!我希望您提交答案,以便我将其评为最佳答案。太感谢了! :) 我不得不编辑新的 GsonRequest

标签: android android-volley android-debug


【解决方案1】:

'Raw type' 表示你没有指定类型参数。 final GsonRequest&lt;SeatRequestModel&gt; gsonRequest = new GsonRequest&lt;&gt;( 应该代替 final GsonRequest gsonRequest = new GsonRequest(。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    相关资源
    最近更新 更多