android - Listfragment crashes when tab selected and gives errors -
when run app runs until select third tab consist listfragment made displays listview data , image, once selected app gives normal message unfortunately app stopped working , logcat sends lot of red errors.
03-06 01:44:23.200: d/dalvikvm(879): gc_for_alloc freed 99k, 6% free 3113k/3280k, paused 57ms, total 59ms 03-06 01:44:23.410: d/dalvikvm(879): gc_for_alloc freed 20k, 5% free 3143k/3280k, paused 20ms, total 21ms 03-06 01:44:23.410: i/dalvikvm-heap(879): grow heap (frag case) 3.811mb 709972-byte allocation 03-06 01:44:23.450: d/dalvikvm(879): gc_for_alloc freed <1k, 4% free 3836k/3976k, paused 33ms, total 33ms 03-06 01:44:23.530: d/(879): hostconnection::get() new host connection established 0xb7a51a38, tid 879 03-06 01:44:23.690: w/egl_emulation(879): eglsurfaceattrib not implemented 03-06 01:44:23.700: d/openglrenderer(879): enabling debug mode 0 03-06 01:44:35.760: d/androidruntime(879): shutting down vm 03-06 01:44:35.760: w/dalvikvm(879): threadid=1: thread exiting uncaught exception (group=0xb4aa8ba8) 03-06 01:44:35.810: e/androidruntime(879): fatal exception: main 03-06 01:44:35.810: e/androidruntime(879): process: com.tipa.uips, pid: 879 03-06 01:44:35.810: e/androidruntime(879): java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.listfragment.ensurelist(listfragment.java:344) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.listfragment.onviewcreated(listfragment.java:145) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:941) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1467) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:472) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.view.viewpager.populate(viewpager.java:1068) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:550) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:509) 03-06 01:44:35.810: e/androidruntime(879): @ android.support.v4.view.viewpager.setcurrentitem(viewpager.java:490) 03-06 01:44:35.810: e/androidruntime(879): @ com.tipa.uips.mainactivity.ontabselected(mainactivity.java:71) 03-06 01:44:35.810: e/androidruntime(879): @ com.android.internal.app.actionbarimpl.selecttab(actionbarimpl.java:577) 03-06 01:44:35.810: e/androidruntime(879): @ com.android.internal.app.actionbarimpl$tabimpl.select(actionbarimpl.java:1105) 03-06 01:44:35.810: e/androidruntime(879): @ com.android.internal.widget.scrollingtabcontainerview$tabclicklistener.onclick(scrollingtabcontainerview.java:547) 03-06 01:44:35.810: e/androidruntime(879): @ android.view.view.performclick(view.java:4438) 03-06 01:44:35.810: e/androidruntime(879): @ android.view.view$performclick.run(view.java:18422) 03-06 01:44:35.810: e/androidruntime(879): @ android.os.handler.handlecallback(handler.java:733) 03-06 01:44:35.810: e/androidruntime(879): @ android.os.handler.dispatchmessage(handler.java:95) 03-06 01:44:35.810: e/androidruntime(879): @ android.os.looper.loop(looper.java:136) 03-06 01:44:35.810: e/androidruntime(879): @ android.app.activitythread.main(activitythread.java:5017) 03-06 01:44:35.810: e/androidruntime(879): @ java.lang.reflect.method.invokenative(native method) 03-06 01:44:35.810: e/androidruntime(879): @ java.lang.reflect.method.invoke(method.java:515) 03-06 01:44:35.810: e/androidruntime(879): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 03-06 01:44:35.810: e/androidruntime(879): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 03-06 01:44:35.810: e/androidruntime(879): @ dalvik.system.nativestart.main(native method) 03-06 01:44:39.230: i/process(879): sending signal. pid: 879 sig: 9
the main thing changed in class use extends fragment
extends listfragment
believe creating error although not sure how?
package com.tipa.uips; import com.tipa.uips.r; import android.os.bundle; import android.support.v4.app.listfragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.content.context; import android.widget.arrayadapter; import android.widget.imageview; import android.widget.listview; import android.widget.textview; import android.widget.toast; public class friendslist extends listfragment { public class mylistadapter extends arrayadapter<string> { context mycontext; public mylistadapter(context context, int textviewresourceid, string[] objects) { super(context, textviewresourceid, objects); mycontext = context; } @override public view getview(int position, view convertview, viewgroup parent) { //return super.getview(position, convertview, parent); layoutinflater inflater = (layoutinflater)mycontext.getsystemservice(context.layout_inflater_service); view row=inflater.inflate(r.layout.row, parent, false); textview label=(textview)row.findviewbyid(r.id.carrottop); label.settext(month[position]); imageview icon=(imageview)row.findviewbyid(r.id.dp); //customize icon here icon.setimageresource(r.drawable.dp); return row; } } string[] month ={ "^smithy", "^kreso", "^chen", "^dave" }; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); /* listadapter mylistadapter = new arrayadapter<string>( getactivity(), android.r.layout.simple_list_item_1, month); setlistadapter(mylistadapter); */ mylistadapter mylistadapter = new mylistadapter(getactivity(), r.layout.row, month); setlistadapter(mylistadapter); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.friends_list, container, false); } @override public void onlistitemclick(listview l, view v, int position, long id) { toast.maketext( getactivity(), getlistview().getitematposition(position).tostring(), toast.length_long).show(); } }
this here adapter allow fragments return values of each class believing not allowing it.
package com.tipa.uips; import com.tipa.uips.newsfeed; import com.tipa.uips.chat; import com.tipa.uips.friendslist; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; public class tabspageradapter extends fragmentpageradapter { public tabspageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int index) { switch (index) { case 0: // top rated fragment activity return new newsfeed(); case 1: // games fragment activity return new chat(); case 2: // movies fragment activity return new friendslist(); } return null; } @override public int getcount() { // item count - equal number of tabs return 3; } }
cheers
update:
new error occuring when implemented listview in xml id/list.
03-06 02:47:59.780: d/dalvikvm(858): not late-enabling checkjni (already on) 03-06 02:48:02.290: d/dalvikvm(858): gc_for_alloc freed 95k, 6% free 3117k/3284k, paused 52ms, total 54ms 03-06 02:48:02.510: d/dalvikvm(858): gc_for_alloc freed 19k, 5% free 3143k/3284k, paused 31ms, total 32ms 03-06 02:48:02.510: i/dalvikvm-heap(858): grow heap (frag case) 3.815mb 709972-byte allocation 03-06 02:48:02.550: d/dalvikvm(858): gc_for_alloc freed <1k, 4% free 3836k/3980k, paused 29ms, total 29ms 03-06 02:48:02.640: d/(858): hostconnection::get() new host connection established 0xb74f2a38, tid 858 03-06 02:48:02.750: w/egl_emulation(858): eglsurfaceattrib not implemented 03-06 02:48:02.760: d/openglrenderer(858): enabling debug mode 0 03-06 02:48:07.920: d/androidruntime(858): shutting down vm 03-06 02:48:07.920: w/dalvikvm(858): threadid=1: thread exiting uncaught exception (group=0xb4a74ba8) 03-06 02:48:07.940: e/androidruntime(858): fatal exception: main 03-06 02:48:07.940: e/androidruntime(858): process: com.tipa.uips, pid: 858 03-06 02:48:07.940: e/androidruntime(858): java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.listfragment.ensurelist(listfragment.java:344) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.listfragment.onviewcreated(listfragment.java:145) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:941) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1467) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:472) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.view.viewpager.populate(viewpager.java:1068) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:550) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:509) 03-06 02:48:07.940: e/androidruntime(858): @ android.support.v4.view.viewpager.setcurrentitem(viewpager.java:490) 03-06 02:48:07.940: e/androidruntime(858): @ com.tipa.uips.mainactivity.ontabselected(mainactivity.java:71) 03-06 02:48:07.940: e/androidruntime(858): @ com.android.internal.app.actionbarimpl.selecttab(actionbarimpl.java:577) 03-06 02:48:07.940: e/androidruntime(858): @ com.android.internal.app.actionbarimpl$tabimpl.select(actionbarimpl.java:1105) 03-06 02:48:07.940: e/androidruntime(858): @ com.android.internal.widget.scrollingtabcontainerview$tabclicklistener.onclick(scrollingtabcontainerview.java:547) 03-06 02:48:07.940: e/androidruntime(858): @ android.view.view.performclick(view.java:4438) 03-06 02:48:07.940: e/androidruntime(858): @ android.view.view$performclick.run(view.java:18422) 03-06 02:48:07.940: e/androidruntime(858): @ android.os.handler.handlecallback(handler.java:733) 03-06 02:48:07.940: e/androidruntime(858): @ android.os.handler.dispatchmessage(handler.java:95) 03-06 02:48:07.940: e/androidruntime(858): @ android.os.looper.loop(looper.java:136) 03-06 02:48:07.940: e/androidruntime(858): @ android.app.activitythread.main(activitythread.java:5017) 03-06 02:48:07.940: e/androidruntime(858): @ java.lang.reflect.method.invokenative(native method) 03-06 02:48:07.940: e/androidruntime(858): @ java.lang.reflect.method.invoke(method.java:515) 03-06 02:48:07.940: e/androidruntime(858): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 03-06 02:48:07.940: e/androidruntime(858): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 03-06 02:48:07.940: e/androidruntime(858): @ dalvik.system.nativestart.main(native method) 03-06 02:48:09.880: i/process(858): sending signal. pid: 858 sig: 9
friends_list.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="vertical" > <listview android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" > </listview> </linearlayout>
you need have listview id below in friends_list.xml
<listview android:id="@android:id/list"
whatever applies listactivity
applies listfragment
. more info @
quoting docs
listactivity has default layout consists of single, full-screen list in center of screen. however, if desire, can customize screen layout setting own view layout setcontentview() in oncreate(). this, own view must contain listview object id "@android:id/list" (or list if it's in code)
so if inflate layout in listfragment
need have listview
id @android:id/list
in fragments layout.
edit:
notice android:id="@+id/list"
vs android:id="@android:id/list"
. suggested android:id="@android:id/list"
Comments
Post a Comment