android - GSON using Volley in Fragment - Errors -


i trying parse json using gson in fragment using volley. getting compile time error @ 2 places

  1. new response.listener<string> : saying listener cannot resolved

  2. new response.errorlistener() : saying errorlistener cannot resolved

  3. cannot resolve method "fromjson"

    public class gson extends fragment  {      recyclerview recyclerview;     response responseobj;     customadapter customadapter;     string url = "https://newsapi.org/v1/articles?source=techcrunch&apikey=ed28d2d13805495a9b896ecb0c7b6ed1";     gson gson;     requestqueue requestqueue;      @nullable     @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate)      {          view view = inflater.inflate(r.layout.gson, container, false);          recyclerview = (recyclerview) view.findviewbyid(r.id.movielist);          requestqueue = volley.newrequestqueue(getactivity().getapplicationcontext());          stringrequest stringrequest = new stringrequest( com.android.volley.request.method.get, url, new response.listener<string>()          {                     @override                     public void onresponse(string response)                      {                         // response                          gson = new gson();                         responseobj = gson.fromjson(response, response.class);                         customadapter = new customadapter(getactivity().getapplicationcontext(), responseobj.getarticles());                         recyclerview.setadapter(customadapter);                      }                 },                 new response.errorlistener()                  {                     @override                     public void onerrorresponse(volleyerror error)                      {                         // handle error                     }          });          //returning our layout file         //change r.layout.yourlayoutfilename each of fragments         requestqueue.add(stringrequest);         return view;      }       @override     public void onviewcreated(view view, @nullable bundle savedinstancestate)      {         super.onviewcreated(view, savedinstancestate);         //you can set title toolbar here different fragments different titles         getactivity().settitle("gson parsing");     } } 

i think problem in response class, should according link:

public class yourresponse {     @serializedname("status")     public string status;     @serializedname("source")     public string source;     @serializedname("sortby")     public string sortby;     @serializedname("articles")     public list<articles> articles;      public static class articles {         @serializedname("author")         public string author;         @serializedname("title")         public string title;         @serializedname("description")         public string description;         @serializedname("url")         public string url;         @serializedname("urltoimage")         public string urltoimage;         @serializedname("publishedat")         public string publishedat;     } } 

secondly change fragment name (maybe u did import error)

public class fragmentgson extends fragment  

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -