android - getting exception while running these code how to resolve -


here adding 2 numers reading values edittext throws exetion how resolve . seems correct. please me package com.example.centum.addition1;

import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.toast;  import static android.app.pendingintent.getactivity; import static android.widget.toast.length_long; import static com.example.centum.addition1.r.id.et1; import static com.example.centum.addition1.r.id.et2;  public class mainactivity extends appcompatactivity {     public edittext etext1,etext2;     public textview tview1;     public button button1;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         etext1=(edittext)findviewbyid(r.id.et1);         etext2=(edittext)findviewbyid(r.id.et2);         button1=(button)findviewbyid(r.id.b1);         tview1=(textview)findviewbyid(r.id.tv1);          button1.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 try{                     string num1,num2;                     num1=etext1.gettext().tostring();                     num2=etext2.gettext().tostring();                     int = integer.parseint(num1);                     int j = integer.parseint(num2);                     int k=i+j;                     toast.maketext(mainactivity.this, k, length_long).show();                  }catch(exception e)                 {                     toast.maketext(mainactivity.this, "error", length_long).show();                 }             }         });     } } 

i found exception, in toast in trying print value of sum of 2 number. toast shows string value in code provide int value. cause of exception.

  toast.maketext(mainactivity.this, k, length_long).show(); 

you have replace above mention line this:

 toast.maketext(mainactivity.this, string.valueof(k),length_long).show(); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -