Why am i getting stackoverflow error in android-pageradapter? -
i want inflate 1 xml file , show in viewpager pages.
lll
logcat:
fatal exception: main java.lang.stackoverflowerror @ android.graphics.drawable.bitmapdrawable.setalpha(bitmapdrawable.java:406) @ android.graphics.drawable.drawablecontainer.jumptocurrentstate(drawablecontainer.java:179) @ android.widget.compoundbutton.jumpdrawablestocurrentstate(compoundbutton.java:319) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgroup.jumpdrawablestocurrentstate(viewgroup.java:5158) @ android.view.viewgr
pageradapter class:
public class pageradapter extends pageradapter { context mcontext; layoutinflater mlayoutinflater; list<string> l = mainactivity.list; imageloader mimageloader; public pageradapter(context context) { mcontext = context; mlayoutinflater = layoutinflater.from(mcontext.getapplicationcontext()); } @override public int getcount() { return 4; } @override public object instantiateitem(viewgroup container, int position) { // view itemview = mlayoutinflater.inflate(r.layout.img, container, false); // imageloader mimageloader = imageloader.getinstance(); view view = mlayoutinflater.inflate(r.layout.createnew, container); // imageview imageview = (imageview) itemview.findviewbyid(r.id.imageview3); // mimageloader.displayimage("http://www.airtel.in/4g/images/airtel_4g_hotspot_responsive.jpg", imageview); container.addview(view); return view; } @override public void destroyitem(viewgroup container, int position, object object) { container.removeview((linearlayout) object); } @override public boolean isviewfromobject(view view, object object) { return view == object; } }
xml file want inflate , show in viewpager ,same in 4 pages:->
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new radiobutton" android:id="@+id/radiobutton" android:layout_gravity="center_horizontal" /> <switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new switch" android:id="@+id/switch1" android:layout_gravity="center_horizontal" /> </linearlayout>
your instantiateitem()
returns container view of viewpager
instead of item go inside container.
this particular nastiness of inflate()
, has bitten many before: if call inflate(r.layout.createnew, container)
, returns container view:
returns
the root view of inflated hierarchy. if root supplied, root view; otherwise root of inflated xml file.
(emphasis partially mine)
you don't access actual root of inflated hierarchy, container new child view attached.
in case, addview()
redundant, because new view in container. in code, however, adds container itself. android not check loops in view hierarchy, infinite traversal loop @ point (causing stackoverflowerror
).
since instanceitem()
needs return (child) view, little bit of problem:
returns object representing new page. not need view, can other container of page.
to prevent new view added container, change call to
view view = inflate(r.layout.createnew, container, false)
;
and leave call addview()
is. necessary, since adapter required add view container:
the adapter responsible adding view container given here, [...]
Comments
Post a Comment