android - What does this mean? How do I fix it? Fatal Exception:main -
i try open android studio app in emulator , giving error:
12-06 00:50:30.993 1198-1198/com.coding.nero e/androidruntime﹕ fatal exception: main process: com.coding.nero, pid: 1198 java.lang.nullpointerexception @ android.support.v4.app.backstackrecord.doaddop(backstackrecord.java:394) @ android.support.v4.app.backstackrecord.add(backstackrecord.java:389) @ android.support.v4.app.fragmentpageradapter.instantiateitem(fragmentpageradapter.java:99) @ android.support.v4.view.viewpager.addnewitem(viewpager.java:832) @ android.support.v4.view.viewpager.populate(viewpager.java:982) @ android.support.v4.view.viewpager.populate(viewpager.java:914) @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1436) @ android.view.view.measure(view.java:16497) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:16497) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) @ com.android.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:327) @ android.view.view.measure(view.java:16497) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2291) @ android.view.view.measure(view.java:16497) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1916) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1113) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1295) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1000) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5670) @ android.view.choreographer$callbackrecord.run(choreographer.java:761) @ android.view.choreographer.docallbacks(choreographer.java:574) @ android.view.choreographer.doframe(choreographer.java:544) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5017) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) @ dalvik.system.nativestart.main(native method)
i have no idea means or how can fix it. can provide more code if necessary. when open in emulator says app has crashed , closes.
here main activity xml file
<android.support.v4.view.viewpager android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/pager" xmlns:android="http://schemas.android.com/apk/res/android">
here mainactivity java
package com.coding.nero; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.view.viewpager; import android.support.v4.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; public class mainactivity extends fragmentactivity { viewpager viewpager=null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); viewpager= (viewpager) findviewbyid(r.id.pager); fragmentmanager fragmentmanager=getsupportfragmentmanager(); viewpager.setadapter(new myadapter(fragmentmanager)); } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmenta extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_a, container, false); } } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmentb extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_a, container, false); } } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmentc extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_a, container, false); } } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmentd extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_d, container, false); } } } class myadapter extends fragmentpageradapter{ public myadapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int i) { fragment fragment=null; if(i==0){ fragment=new fragmenta_1(); } if(i==1){ fragment=new fragmentb_1(); } if(i==2){ fragment=new fragmentc_1(); } if(i==3){ fragment=new fragmentd_1(); } return null; } @override public int getcount() { return 4; }
adapter code:
package com.coding.nero; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.view.viewpager; import android.support.v4.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; public class mainactivity extends fragmentactivity { viewpager viewpager=null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); viewpager= (viewpager) findviewbyid(r.id.pager); fragmentmanager fragmentmanager=getsupportfragmentmanager(); viewpager.setadapter(new myadapter(fragmentmanager)); } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmenta extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_a, container, false); } } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmentb extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_a, container, false); } } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmentc extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_a, container, false); } } /** * created john on 12/5/14. */ //links class layout file fragment_a public static class fragmentd extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_d, container, false); } } } class myadapter extends fragmentpageradapter{ public myadapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int i) { fragment fragment=null; if(i==0){ fragment=new fragmenta_1(); } if(i==1){ fragment=new fragmentb_1(); } if(i==2){ fragment=new fragmentc_1(); } if(i==3){ fragment=new fragmentd_1(); } return null; } @override public int getcount() { return (4); } }
because adapter "getitem()" returns null.
Comments
Post a Comment