java - How do I get List<Pojo1> which is present in its root Pojo, which also returns as a List<Pojo> -


i parsing ola cabs api response comes this:

{   "categories": [ {   "id": "mini",   "display_name": "mini",   "currency": "inr",   "distance_unit": "kilometre",   "time_unit": "minute",   "eta": 1,   "distance": "0.2",   "ride_later_enabled": "true",   "image": "http://d1foexe15giopy.cloudfront.net/mini.png",   "fare_breakup": [     {       "type": "flat_rate",       "minimum_distance": "4",       "minimum_time": "0",       "base_fare": "80",       "minimum_fare": "0",       "cost_per_distance": "10",       "waiting_cost_per_minute": "0",       "ride_cost_per_minute": "1",       "rates_higher_than_usual": false,       "surcharge": []     },     {       "type": "airport_rate",       "minimum_distance": "25",       "minimum_time": "0",       "base_fare": "499",       "minimum_fare": "0",       "cost_per_distance": "13",       "waiting_cost_per_minute": "0",       "ride_cost_per_minute": "1",       "rates_higher_than_usual": false,       "surcharge": []     }   ],   "cancellation_policy": {     "cancellation_charge": 50,     "currency": "inr",     "cancellation_charge_applies_after_time": 5,     "time_unit": "minute"   } } ], "ride_estimate": {} } 

i've created model classes as:

public class listofestimatetimeforola() { list<categories> categories; //getter of categories } 

above class main pojo response. below given pojo named- categories.

public class categories() { list<fare_breakup>; //getter of fare_breakup  } 

and there's model defined fare_breakup this:

  public class fare_breakup {    int base_fare;     //getter of fare    } 

now, response in fragment, code below:

requestinterface = retrofit.create(riderequestinterface.class);         if (pickup_lat != 0 && pickup_long != 0 ) {             call<listofestimatetimeforola> pricedata = requestinterface.getestimatetimeforola(pickup_lat, pickup_long);             pricedata.enqueue(new callback<listofestimatetimeforola>() {                 @override                 public void onresponse(@nonnull call<listofestimatetimeforola> call, @nonnull response<listofestimatetimeforola> response) {                     int statuscode = response.code();                      listofestimatetimeforola data = response.body();                      assert data != null;                      estimatetimeadapterforola adapter = new estimatetimeadapterforola(data.getcategories(), getcontext());                     estimatepriceforola.setadapter(adapter);                      progressforola.setvisibility(view.gone);                     estimatepriceforola.setvisibility(view.visible);                     log.d("estimated time ola", "onresponse: "+ statuscode);                 }                  @override                 public void onfailure(@nonnull call<listofestimatetimeforola> call, @nonnull throwable t) {                     log.d("estimated time ola", "onresponse: "+ t.getmessage());                 }             });         } 

i need fare in recyclerview adapter class below:

public class estimatetimeadapterforola extends recyclerview.adapter<estimatetimeadapterforola.estimatetimeholder>{  private context c; private list<estimatetimeforola> estimatetimeforola;  public estimatetimeadapterforola (list<estimatetimeforola> estimatetimeforola, context c) {     this.estimatetimeforola = estimatetimeforola;     this.c = c; }  @override public estimatetimeholder oncreateviewholder(viewgroup parent, int viewtype) {     view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.estimate_time_for_ola, parent, false);     estimatetimeholder holder = new estimatetimeholder(view);     return holder; }  @override public void onbindviewholder(estimatetimeholder holder, int position) {      holder.displayname.settext(estimatetimeforola.get(position).getdisplay_name());     picasso.with(c).load(estimatetimeforola.get(position).getimage()).into(holder.displayicon);     holder.fare.settext(string.valueof(estimatetimeforola.get(position).getfare_breakup().get(0).getbase_fare()));     holder.eta.settext(string.valueof(estimatetimeforola.get(position).geteta())); }  @override public int getitemcount() {     return estimatetimeforola.size(); }  public static class estimatetimeholder extends recyclerview.viewholder {      textview displayname, fare, eta;     imageview displayicon;      public estimatetimeholder(view itemview) {         super(itemview);          displayname = itemview.findviewbyid(r.id.display_name_ola_tv);         fare = itemview.findviewbyid(r.id.actual_fare_tv);         eta = itemview.findviewbyid(r.id.actual_eta_tv);         displayicon = itemview.findviewbyid(r.id.display_icon_ola_iv);     } } } 

now, problem how fare in recyclerview through onbindviewholder?

below given error after running above code:

07-28 17:27:50.134 330-330/test.android.mobond.tabs.slidingtabs e/androidruntime: fatal exception: main                                                                               process: test.android.mobond.tabs.slidingtabs, pid: 330                                                                               java.lang.nullpointerexception: attempt invoke interface method 'java.lang.object java.util.list.get(int)' on null object reference                                                                                   @ test.android.mobond.tabs.slidingtabs.adapters.estimatetimeadapterforola.onbindviewholder(estimatetimeadapterforola.java:45)                                                                                   @ test.android.mobond.tabs.slidingtabs.adapters.estimatetimeadapterforola.onbindviewholder(estimatetimeadapterforola.java:22)                                                                                   @ android.support.v7.widget.recyclerview$adapter.onbindviewholder(recyclerview.java:6400)                                                                                   @ android.support.v7.widget.recyclerview$adapter.bindviewholder(recyclerview.java:6433)                                                                                   @ android.support.v7.widget.recyclerview$recycler.trybindviewholderbydeadline(recyclerview.java:5377)                                                                                   @ android.support.v7.widget.recyclerview$recycler.trygetviewholderforpositionbydeadline(recyclerview.java:5640)                                                                                   @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5482)                                                                                   @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:5478)                                                                                   @ android.support.v7.widget.linearlayoutmanager$layoutstate.next(linearlayoutmanager.java:2215)                                                                                   @ android.support.v7.widget.linearlayoutmanager.layoutchunk(linearlayoutmanager.java:1542)                                                                                   @ android.support.v7.widget.linearlayoutmanager.fill(linearlayoutmanager.java:1502)                                                                                   @ android.support.v7.widget.linearlayoutmanager.onlayoutchildren(linearlayoutmanager.java:595)                                                                                   @ android.support.v7.widget.recyclerview.dispatchlayoutstep2(recyclerview.java:3625)                                                                                   @ android.support.v7.widget.recyclerview.onmeasure(recyclerview.java:3067)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5908)                                                                                   @ android.widget.framelayout.onmeasure(framelayout.java:436)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1629)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:728)                                                                                   @ android.widget.relativelayout.onmeasure(relativelayout.java:464)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5908)                                                                                   @ android.widget.framelayout.onmeasure(framelayout.java:436)                                                                                   @ android.support.v7.widget.contentframelayout.onmeasure(contentframelayout.java:139)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5908)                                                                                   @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1435)                                                                                   @ android.widget.linearlayout.measurevertical(linearlayout.java:721)                                                                                   @ android.widget.linearlayout.onmeasure(linearlayout.java:612)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5908)                                                                                   @ android.widget.framelayout.onmeasure(framelayout.java:436)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5908)                                                                                   @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1435)                                                                                   @ android.widget.linearlayout.measurevertical(linearlayout.java:721)                                                                                   @ android.widget.linearlayout.onmeasure(linearlayout.java:612)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5908)                                                                                   @ android.widget.framelayout.onmeasure(framelayout.java:436)                                                                                   @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:3076)                                                                                   @ android.view.view.measure(view.java:18870)                                                                                   @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2392)                                                                                   @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1416)                                                                                   @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1661)                                                                                   @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1301)                                                                                   @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:7016)                                                                                   @ android.view.choreographer$callbackrecord.run(choreographer.java:777)                                                                                   @ android.view.choreographer.docallbacks(choreographer.java:590)                                                                                 @ android.view.choreog 

create pojos using json2pojo create adequate pojo classes , use retrofit


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -