Android fragment stackoverflow -
when instantiate fragment stackoverflow error. i'm trying have fragment selected using navigation drawer defined in main activity class.
public class myfragment extends fragment { public static myfragment newinstance() { return new myfragment(); } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.page_meet, container, false); } public void onviewcreated(view view, bundle savedinstancestate) { viewpager mviewpager = (viewpager) view.findviewbyid(r.id.pager); myfragmentpageradapter mviewpageradapter = new myfragmentpageradapter(getchildfragmentmanager()); mviewpager.setadapter(mviewpageradapter); } public class myfragmentpageradapter extends fragmentpageradapter { public myfragmentpageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int position) { return newinstance(); } @override public int getcount() { return 2; } } }
here xml file page_meet.xml:
<android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#00ff00" > </linearlayout> </android.support.v4.view.viewpager>
logcat wasn't informative:
10-07 03:19:27.910: e/androidruntime(27875): fatal exception: main 10-07 03:19:27.910: e/androidruntime(27875): java.lang.stackoverflowerror 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11890) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirection(view.java:11892) 10-07 03:19:27.910: e/androidruntime(27875): @ android.view.view.canresolvelayoutdirec
i wrote answer without realizing had viewpager
inside xml fragment
. intention myfragment
contain other fragment
s? if not, design not correct. viewpager
belongs in layout used in activity
. if want show other fragment
s inside myfragment
, see here.
original answer: problem creating new myfragmentpageradapter
in onviewcreated
of fragment
itself. pager adapter should not inner class of fragment
. pager adapter works view pager in activity
determine type of fragment
should shown @ given time.
edit: because saw comment on other answer, getitem
should return new instance of fragment
. not underlying problem.
Comments
Post a Comment