android - java.lang.RuntimeException: Unable to start activity ComponentInfo {...}: java.lang.NullPointerException -
when click go 1 activity another, have error:
java.lang.runtimeexception: unable start activity componentinfo {...}: java.lang.nullpointerexception
i missing method? please me understand did wrong, why see error?
my activity: zaselenie.java
import java.util.arraylist; import android.app.activity; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.util.log; import android.widget.arrayadapter; import android.widget.spinner; public class zaselenie extends activity { contactdbmoy cqh; kvartdb kdb; sqlitedatabase sdb; private long rowid; spinner spzaselenie; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.zaselenie); spzaselenie = (spinner)findviewbyid(r.id.spzaselenie); // Инициализируем наш класс-обёртку cqh = new contactdbmoy(zaselenie.this); kdb = new kvartdb(zaselenie.this); // База нам нужна для записи и чтения sdb = cqh.getwritabledatabase(); sdb = kdb.getwritabledatabase(); bundle extras = getintent().getextras(); rowid = extras.getlong(contactmain.rowid); cursor cursorkvart = sdb.query(kvartdb.table_name, new string[] { kvartdb._id, kvartdb.name_column }, null, // // columns // // // clause null, // values clause null, // don't group rows null, // don't filter row groups null // sort order ); arraylist<string> labels = new arraylist<string>(); while (cursorkvart.movetonext()) { // column indices + values of columns int idkvart = cursorkvart.getint(cursorkvart.getcolumnindex(kvartdb._id)); string namekvart = cursorkvart.getstring(cursorkvart.getcolumnindex(kvartdb.name_column)); log.i("log_tag", "row " + idkvart + " has name " + namekvart); labels.add(namekvart); // creating adapter spinner arrayadapter<string> dataadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, labels); // drop down layout style - list view radio button dataadapter .setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); dataadapter.notifydatasetchanged(); // attaching data adapter spinner spzaselenie.setadapter(dataadapter); } cursorkvart.close(); } public zaselenie() { // todo auto-generated constructor stub } @override protected void onresume() { super.onresume(); } @override protected void onstop() { super.onstop(); // закрываем соединения с базой данных sdb.close(); kdb.close(); } }
logcat error:
03-06 12:04:43.802: e/androidruntime(20861): fatal exception: main 03-06 12:04:43.802: e/androidruntime(20861): java.lang.runtimeexception: unable start activity componentinfo{ru.zloyel.manager_sutochnoy_arendy_1/ru.zloyel.manager_sutochnoy_arendy_1.zaselenie}: java.lang.nullpointerexception 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activitythread.access$600(activitythread.java:130) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 03-06 12:04:43.802: e/androidruntime(20861): @ android.os.handler.dispatchmessage(handler.java:99) 03-06 12:04:43.802: e/androidruntime(20861): @ android.os.looper.loop(looper.java:137) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activitythread.main(activitythread.java:4745) 03-06 12:04:43.802: e/androidruntime(20861): @ java.lang.reflect.method.invokenative(native method) 03-06 12:04:43.802: e/androidruntime(20861): @ java.lang.reflect.method.invoke(method.java:511) 03-06 12:04:43.802: e/androidruntime(20861): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 03-06 12:04:43.802: e/androidruntime(20861): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 03-06 12:04:43.802: e/androidruntime(20861): @ dalvik.system.nativestart.main(native method) 03-06 12:04:43.802: e/androidruntime(20861): caused by: java.lang.nullpointerexception 03-06 12:04:43.802: e/androidruntime(20861): @ ru.zloyel.manager_sutochnoy_arendy_1.zaselenie.oncreate(zaselenie.java:39) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activity.performcreate(activity.java:5008) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 03-06 12:04:43.802: e/androidruntime(20861): @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 03-06 12:04:43.802: e/androidruntime(20861): ... 11 more
check extras
isn't null
below...
if(extras != null) { rowid = extras.getlong(contactmain.rowid); }
also check cursor
object isn't null below...
if(cursorkvart != null && cursorkvart.getcount() > 0) { while (cursorkvart.movetonext()) { ...... } }
Comments
Post a Comment