Sunday, 15 September 2013

java - Null pointer exception listview -



java - Null pointer exception listview -

i've been searching solution , can't seem find works, it's simple listview icon , text, i've overlooked stupid appreciate if take look. :)

here java: storepick.java

package com.ctc.android.widget; import android.os.bundle; import android.widget.listview; import android.app.activity; import android.widget.arrayadapter; public class storepick extends activity { string[] data={"morningside","primross"}; listview lv; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.storepick); lv= (listview) findviewbyid(r.id.listview3); arrayadapter<string> adapter=new arrayadapter<string>(this,r.layout.listview_layout,r.id.txtview1,data); lv.setadapter(adapter); } }

my xml: storepick.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <listview android:id="@+id/listview3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" > </listview>

my listview layout: listview_layout.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bpicon" /> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textappearance="?android:attr/textappearancelarge" />

here stack trace

10-23 10:09:12.916: w/dalvikvm(31213): threadid=1: thread exiting uncaught exception (group=0x4180ada0) 10-23 10:09:12.926: e/androidruntime(31213): fatal exception: main 10-23 10:09:12.926: e/androidruntime(31213): process: com.ctc.android.widget, pid: 31213 10-23 10:09:12.926: e/androidruntime(31213): java.lang.nullpointerexception 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.arrayadapter.createviewfromresource(arrayadapter.java:392) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.arrayadapter.getview(arrayadapter.java:362) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.abslistview.obtainview(abslistview.java:2765) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.listview.measureheightofchildren(listview.java:1274) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.listview.onmeasure(listview.java:1186) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.view.measure(view.java:17479) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.relativelayout.measurechild(relativelayout.java:689) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.relativelayout.onmeasure(relativelayout.java:473) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.view.measure(view.java:17479) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5364) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.framelayout.onmeasure(framelayout.java:310) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.view.measure(view.java:17479) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5364) 10-23 10:09:12.926: e/androidruntime(31213): @ com.android.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:412) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.view.measure(view.java:17479) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5364) 10-23 10:09:12.926: e/androidruntime(31213): @ android.widget.framelayout.onmeasure(framelayout.java:310) 10-23 10:09:12.926: e/androidruntime(31213): @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2532) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.view.measure(view.java:17479) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2262) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1391) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1590) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1249) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6585) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.choreographer$callbackrecord.run(choreographer.java:803) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.choreographer.docallbacks(choreographer.java:603) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.choreographer.doframe(choreographer.java:573) 10-23 10:09:12.926: e/androidruntime(31213): @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:789) 10-23 10:09:12.926: e/androidruntime(31213): @ android.os.handler.handlecallback(handler.java:733) 10-23 10:09:12.926: e/androidruntime(31213): @ android.os.handler.dispatchmessage(handler.java:95) 10-23 10:09:12.926: e/androidruntime(31213): @ android.os.looper.loop(looper.java:136) 10-23 10:09:12.926: e/androidruntime(31213): @ android.app.activitythread.main(activitythread.java:5586) 10-23 10:09:12.926: e/androidruntime(31213): @ java.lang.reflect.method.invokenative(native method) 10-23 10:09:12.926: e/androidruntime(31213): @ java.lang.reflect.method.invoke(method.java:515) 10-23 10:09:12.926: e/androidruntime(31213): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1268) 10-23 10:09:12.926: e/androidruntime(31213): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1084) 10-23 10:09:12.926: e/androidruntime(31213): @ dalvik.system.nativestart.main(native method)

android:id="@+id/textview1" it's different r.id.txtview1

change adapter

arrayadapter<string> adapter=new arrayadapter<string>(this,r.layout.listview_layout,r.id.textview1,data);

java android xml

No comments:

Post a Comment