Woppi Woppi - 5 days ago 4
Android Question

How to solve Unchecked call to 'GsonRequest(Params)' as a member of raw type?

I'm having a warning on my editor.


Unchecked call to 'GsonRequest(int, String, Class, Map, Listener, ErrorListener)' as a member of raw type
'com.inc.woppi.demoapp.GsonRequest'


The GsonRequest class is copied from Android Dev: https://developer.android.com/training/volley/request-custom.html

While my call is below:

// 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);

Answer

'Raw type' means that you has not specified type parameter. final GsonRequest<SeatRequestModel> gsonRequest = new GsonRequest<>( should be instead of final GsonRequest gsonRequest = new GsonRequest(.

Comments