android - How to solve "java.lang.NumberFormatException: s == null at java.lang.Integer.parseInt" -


i tried different things solution failed, need know what's wrong code , should be.

here logcat error

e/androidruntime: fatal exception: main                                                                       process: freemig.freemigmessenger, pid: 31699                                                                       java.lang.numberformatexception: s == null                                                                           @ java.lang.integer.parseint(integer.java:570)                                                                           @ java.lang.integer.parseint(integer.java:643) 

and happens on button click event

    private class sentmessageholder extends recyclerview.viewholder {     textview messagetext, timetext;     imagebutton ib;     msgdltapiservice msgdltapiservice;     string rec_id;     string content_id;     int[] ids = new int[100];      sentmessageholder(final view itemview) {         super(itemview);          messagetext = itemview.findviewbyid(r.id.text_message_body);         timetext = itemview.findviewbyid(r.id.text_message_time);         ib = itemview.findviewbyid(r.id.sentmessagetextdelete);         msgdltapiservice = restclient.getclient().create(msgdltapiservice.class);          ib.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 userauthenticationkey = new userauthenticationkey(mcontext.getapplicationcontext());                 sharedpreferences =  mcontext.getapplicationcontext().getsharedpreferences("user authentication", mode_private);                 editor = sharedpreferences.edit();                 ids[0] = integer.parseint(content_id);                 final msgdltrequest msgdltrequest = new msgdltrequest(                         ids,                         rec_id);                 call<msgdltresponse> call =                         msgdltapiservice.msgdlt(userauthenticationkey.getusertokenkey(),                                 msgdltrequest);                 call.enqueue(new callback<msgdltresponse>() {                     @override                     public void onresponse(call<msgdltresponse> call, response<msgdltresponse> response) {                          toast.maketext(mcontext.getapplicationcontext(), "" + response.body().getdata(),                                 toast.length_long).show();                     }                      @override                     public void onfailure(call<msgdltresponse> call, throwable t) {                         toast.maketext(mcontext.getapplicationcontext(), "please try again",                                 toast.length_long).show();                     }                 });             }         });     }      void bind(datum2 message) {         messagetext.settext(message.getmsg());          // format stored timestamp readable string using method.         timetext.settext(message.getcreatedat().getformattime());         content_id.valueof(message.getcontentid().tostring()) ;         if (! message.getoriginatorid().equals(userid)){             rec_id.valueof(message.getoriginatorid());         }         else {             rec_id = null;         }                         }  } 

it gives me error on line

ids[0] = integer.parseint(content_id); 

i tried several things said , should code? full class here. 1 more thing i'm working on adapter class.

you can use textutils utility method this,

if (!textutils.isempty(content_id) && textutils.isdigitsonly(content_id)) {     ids[0] = integer.parseint(content_id); } else {     ids[0] = 0; } 

and while setting content_id can set this, content_id = message.getcontentid().tostring(); instead of content_id.valueof(message.getcontentid().tostring()) ;


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -