java - EROR NullPointerException -


at time need u guys, have following code, when run in eclipse, it's totally eror,(the error sign in code below)

package com.example.search; import java.util.calendar; import android.app.activity; import android.app.datepickerdialog; import android.app.dialog; import android.content.intent; import android.os.bundle; import android.view.motionevent; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.datepicker; import android.widget.edittext; import android.widget.textview; import com.example.database.search.dbdatasource; import com.example.database.search.sma;  public class editdata extends activity implements onclicklistener  {     int hour, minute, myear,mmonth, mday;     static final int date_dialog_id = 1;     private edittext txtdate;     private string[] arrmonth{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"}; private dbdatasource datasource;  private long id; private string nama; private string alamat; private long latitude; private long longtitude; private string tanggal; private string email; private string website; private string facebook; private string twtitter; private edittext ednama_sma, edalamat_sma, edlatitude, edlongtitude, edtanggal, edemail, edwebsite, edfacebook, edtwitter; private textview txid; private button btnsave; private button btncancel; private sma sma;  @override public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setcontentview(r.layout.edit_data);              //inisialisasi variabel       ednama_sma    = (edittext) findviewbyid(r.id.edittext_nama);       edalamat_sma  = (edittext) findviewbyid(r.id.edittext_alamat);       edlatitude    = (edittext) findviewbyid(r.id.edittext_latitude);       edlongtitude  = (edittext) findviewbyid(r.id.edittext_longtitude);       edtanggal     = (edittext) findviewbyid(r.id.edittext_tanggal);       edemail       = (edittext) findviewbyid(r.id.edittext_email);       edwebsite     = (edittext) findviewbyid(r.id.edittext_website);       edfacebook    = (edittext) findviewbyid(r.id.edittext_facebook);       edtwitter     = (edittext) findviewbyid(r.id.edittext_twitter);        txid = (textview) findviewbyid(r.id.text_id_barang);         // current date         final calendar c = calendar.getinstance();         myear   = c.get(calendar.year);         mmonth  = c.get(calendar.month);         mday    = c.get(calendar.day_of_month);         //when  add code below, >> error happend >> java.lang.nullpointerexceptions        //this function use showing datetimepicker          txtdate.setontouchlistener(new view.ontouchlistener() {              @override             public boolean ontouch(view v, motionevent event) {                 // todo auto-generated method stub                 showdialog(date_dialog_id);                 return true;              }         });       //until line       datasource = new dbdatasource(this);       datasource.open();       // ambil data sma dari extras       bundle bun = this.getintent().getextras();       id            = bun.getlong("id");       nama          = bun.getstring("nama");       alamat        = bun.getstring("alamat");       latitude      = bun.getlong("latitude");       longtitude    = bun.getlong("longtitude");       tanggal       = bun.getstring("tanggal");       email         = bun.getstring("email");       website       = bun.getstring("website");       facebook      = bun.getstring("facebook");       twtitter      = bun.getstring("twitter");         txid.append(string.valueof(id));       ednama_sma.settext(nama);       edalamat_sma.settext(alamat);       edlatitude.settext(latitude.tostring());       edlongtitude.settext(longtitude.tostring());       edtanggal.settext(tanggal);       edemail.settext(email);       edwebsite.settext(website);       edfacebook.settext(facebook);       edtwitter.settext(twtitter);       //set listener pada tombol       btnsave = (button) findviewbyid(r.id.button_save_update);       btnsave.setonclicklistener(this);       btncancel = (button) findviewbyid(r.id.button_cancel_update);       btncancel.setonclicklistener(this); } @override protected dialog oncreatedialog(int id) {     switch (id)      {         case date_dialog_id:             return new datepickerdialog(this, mdatesetlistener, myear, mmonth, mday);     }     return null; }  private datepickerdialog.ondatesetlistener mdatesetlistener = new datepickerdialog.ondatesetlistener() {         @override         public void ondateset(datepicker view, int year, int monthofyear,int dayofmonth)          {             myear = year;             mmonth = monthofyear;             mday = dayofmonth;             string sdate = arrmonth[mmonth] + " " + lpad(mday + "", "0", 2) + ", " + myear;             txtdate.settext(sdate);         }     };     private static string lpad(string schar, string spad, int len)      {         string sret = schar;         (int = sret.length(); < len; i++)          {             sret = spad + sret;         }         return new string(sret);     }  @override public void onclick(view v)  {     // todo auto-generated method stub     switch(v.getid())     {     // apabila tombol save diklik (update barang)     case r.id.button_save_update :         string ltd = edlatitude.gettext().tostring();         string lotd = edlongtitude.gettext().tostring();         long latitude = long.parselong(ltd);         long longtitude = long.parselong(lotd);         sma = new sma();         sma.setnama(ednama_sma.gettext().tostring());         sma.setalamat(edalamat_sma.gettext().tostring());         sma.setlatitude(latitude);         sma.setlongitude(longtitude);         sma.setemail(edemail.gettext().tostring());         sma.settgl_berdiri(edtanggal.gettext().tostring());         sma.setwebsite(edwebsite.gettext().tostring());         sma.setfacebook(edfacebook.gettext().tostring());         sma.settwitter(edtwitter.gettext().tostring());          sma.setid(id);         datasource.updatebarang(sma);         intent = new intent(this, viewdata.class);         startactivity(i);         editdata.this.finish();         datasource.close();         break;      case r.id.button_cancel_update :         finish();         datasource.close();         break;     }   } } 

anyone please me error, want thank of u can resolve code, :d

you haven't initialized txtdate etidtext.

txtdate = (edittext) findviewbyid(r.id.txtdate);// or ever add id txtdate 

then fine.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -