android - Null pointer Exception in Custom Adapter while set the value for list item -


i want display conditional data in list view when user request or click on button. each list row has 2 value 1 value name , 2nd description. when user press button fire command , fetch information peripheral , match value different condition 1 one, conditions match value put 1 list row value in adapter after conditions check assign adapter list view, display adapter data display in list view.

this code

public class dtcode extends activity { private final static string tag = dtcode.class.getsimplename();

final static string extra_device_address = "device_address";  public  string mdeviceaddress; public bluetoothleservice mbluetoothleservice; private boolean mconnected = false;  button btnread, btnclear; string receivedata = ""; listview mylist;  errorsadapter adapter;  arraylist<error> arrayoferrors;  error error;  listview listerror; //code service;  private  final serviceconnection mserviceconnection = new serviceconnection() {     @override     public void onserviceconnected(componentname componentname, ibinder service) {         mbluetoothleservice = ((bluetoothleservice.localbinder) service).getservice();         if (!mbluetoothleservice.initialize()){             log.e(tag, "bluetooth not initialize");             finish();         }         log.e(tag,"bluetooth service okay");         mbluetoothleservice.connect(mdeviceaddress);     }      @override     public void onservicedisconnected(componentname componentname) {         mbluetoothleservice = null;     } };  private final broadcastreceiver mgattupdatereceiver= new broadcastreceiver() {     @override     public void onreceive(context context, intent intent) {         final  string action = intent.getaction();         if (bluetoothleservice.action_gatt_connected.equals(action)){             log.e(tag, "only gatt, wait");         } else if (bluetoothleservice.action_gatt_disconnected.equals(action)){             mconnected = false;             invalidateoptionsmenu();             btnclear.setenabled(false);             btnread.setenabled(false);         }else if (bluetoothleservice.action_gatt_services_discovered.equals(action)){             mconnected =true;             btnread.setenabled(true);             log.e(tag,"in need");         }else  if (bluetoothleservice.action_data_available.equals(action)){             log.e(tag,"receive data");              string data = intent.getstringextra(bluetoothleservice.extra_data);              if (data != null){                 btnclear.setenabled(true);                 receivedata = receivedata.concat(data);                  char character = receivedata.charat(receivedata.length() - 1 );                 system.out.println(receivedata);                  if (character == '\n'){                      string[] err = receivedata.split("!");                      (int = 0 ; < err.length ; i++) {                          string[] errcode = err[i].split("_");                          (int j = 0; j < errcode.length; j++) {                              system.out.println(errcode[j]);                              if (errcode[j].startswith("108e07")){                                 error = new error("dim-b108e07", "display failure information");                                 adapter.add(error);                             }else if (errcode[j].startswith("115c71")){                                 error = new error("dim-b115c71", "transfer fuel pump. actuator stuck");                                 adapter.add(error);                             }else if (errcode[j].startswith("1a0107")){                                 error = new error("dim-b1a0107","speaker #1 failure.");                                 adapter.add(error);                             }else if (errcode[j].startswith("1b6916")){                                 error = new error("dim-b1b6916","circuit voltage below threshold.");                                 adapter.add(error);                             }else if (errcode[j].startswith("1b6917")){                                 error = new error("dim-b1b6917","circuit voltage above threshold");                                 adapter.add(error);                             }else if (errcode[j].startswith("1a4815")){                                 error = new error("dim-c1a4815", "short circuit battery or open.");                                 adapter.add(error);                             }else if (errcode[j].startswith("600262")){                                 error = new error("dim-c200262", "odometer tempered");                                 adapter.add(error);                             }else if (errcode[j].startswith("046071")){                                 error = new error("dim-p0460171","fuel level circuit, actuator stuck.");                                 adapter.add(error);                             }else if (errcode[j].startswith("134671")){                                 error = new error("dim-p134671","fuel level b circuit, actuator stuck.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c00155")){                                 error = new error("dim-u000155","high speed can not configured.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c00188")){                                 error = new error("dim-u000188","high speed can bus off.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c01055")){                                 error = new error("dim-u001055","medium speed can not configured.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c01088")){                                 error = new error("dim-u001088","medium speed can bus off.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c10000")){                                 error = new error("dim-u010000","lost communication ecm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c10100")){                                 error = new error("dim-u010100","lost communication tcm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c10400")){                                 error = new error("dim-u010400","lost communication fsm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c12100")){                                 error = new error("dim-u012100","lost communication abs");                                 adapter.add(error);                             }else if (errcode[j].startswith("c14000")){                                 error = new error("dim-u014000","lost communication cem.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c15100")){                                 error = new error("dim-u015100","lost communication srsm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c15600")){                                 error = new error("dim-u015600","lost communication icm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c15900")){                                 error = new error("dim-u015900","lost communication pam.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c25000")){                                 error = new error("dim-u025000","lost communication ppm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c25200")){                                 error = new error("dim-u025200","lost communication trm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c40168")){                                 error = new error("dim-u040168","invalid data received ecm/pcm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c40268")){                                 error = new error("dim-u040268","invalid data received tcm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c41568")){                                 error = new error("dim-u041568","invalid data received abs.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c42268")){                                 error = new error("dim-u042268","invalid data received cem.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c45292")){                                 error = new error("dim-u045292","invalid data received srs.");                                 adapter.add(error);                             }else if (errcode[j].startswith("c55168")){                                 error = new error("dim-u055168","invalid data received ppm.");                                 adapter.add(error);                             }else if (errcode[j].startswith("da4b49")){                                 error = new error("dim-u1a4b49","internal electronic failure.");                                 adapter.add(error);                             }else if (errcode[j].startswith("e10000")){                                 error = new error("dim-u210000","control module not configured.");                                 adapter.add(error);                             }else if (errcode[j].startswith("e10100")){                                 error = new error("dim-u210100","control module configuration incompatible.");                                 adapter.add(error);                             }else if (errcode[j].startswith("f00044")){                                 error = new error("dim-u300044","data memory failure.");                                 adapter.add(error);                             }else if (errcode[j].startswith("f00045")){                                 error = new error("dim-u300045","program memory failure.");                                 adapter.add(error);                             }else if (errcode[j].startswith("f00362")){                                 error = new error("dim-u300362","signal compare failure.");                                 adapter.add(error);                             }                         }                     }                   listerror.setadapter(adapter);                 }             }         }      } };  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_dtcode);      final intent intent = getintent();     mdeviceaddress = intent.getstringextra(extra_device_address);      btnread = (button) findviewbyid(r.id.read);     btnread.setenabled(false);      btnclear= (button) findviewbyid(r.id.clr);     btnclear.setenabled(false);      arrayoferrors = new arraylist<error>();     adapter = new errorsadapter(this, arrayoferrors);      listerror = (listview) findviewbyid(r.id.list);      getactionbar().settitle("tft trouble code");     getactionbar().setdisplayhomeasupenabled(true);     log.d(tag, "try bindservice=" + bindservice(new intent(this, bluetoothleservice.class), mserviceconnection, bind_auto_create));      registerreceiver(mgattupdatereceiver, makegattupdateintentfilter());  }  @override protected void onresume(){     super.onresume();     registerreceiver(mgattupdatereceiver,makegattupdateintentfilter());     if (mbluetoothleservice != null){         final boolean result = mbluetoothleservice.connect(mdeviceaddress);         log.d(tag,"connect result="+ result);     } }  @override protected void onpause(){     super.onpause();     unregisterreceiver(mgattupdatereceiver);     unbindservice(mserviceconnection); }  @override protected  void  ondestroy(){      if (mbluetoothleservice != null){         mbluetoothleservice.close();         mbluetoothleservice = null;     }     log.d(tag, "we in destroy"); }  public void onclick (view v){      if (v == btnread){         if(!mconnected) return;         mbluetoothleservice.writevalue("$dim_re\n");     }     if (v == btnclear){         if(!mconnected) return;         mbluetoothleservice.writevalue("$dim_clr\n");         mylist.setadapter(null);     } }   public  class  errorsadapter extends  arrayadapter<error>{     public errorsadapter(context context, arraylist<error> errors){         super(context, 0, errors);     }      @override     public view getview(int position, view convertview, viewgroup parent){         error error = getitem(position);          if (convertview == null){             convertview = layoutinflater.from(getcontext()).inflate(r.layout.item_error, parent, false);         }          textview ectxt = (textview) findviewbyid(r.id.txt_error_code);         textview edtxt = (textview) findviewbyid(r.id.txt_error_description);          ectxt.settext(error.errorcode);         edtxt.settext(error.errordescription);          return convertview;     } } 

in getview in adapter, replace

textview ectxt = (textview) findviewbyid(r.id.txt_error_code); textview edtxt = (textview) findviewbyid(r.id.txt_error_description); 

with

textview ectxt = (textview) convertview.findviewbyid(r.id.txt_error_code); textview edtxt = (textview) convertview.findviewbyid(r.id.txt_error_description); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -