Saturday, 15 March 2014

android - app crashing while implementing lateral navigation -



android - app crashing while implementing lateral navigation -

i created new activity navigation type "tabs + swipe". made these changes in getitem() method :

@override public fragment getitem(int i) { fragment fragment ; switch(i){ case 0: fragment = new fragment1(); break; case 1: fragment = new fragment2(); break; case 3: fragment = new fragment3(); break; // default : homecoming null; } //set args if necessary //return fragment homecoming fragment; }

so each tab i've defined separate class. 1 of class :

public static class fragment1 extends fragment { /** * fragment argument representing section number * fragment. */ public fragment1() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // create new textview , set text fragment's section // number argument value. view v = inflater.inflate(r.layout.center, null); homecoming v; } }

when run app new activity starts when swipe screen sec tab app crashes... logcat :

02-16 08:48:43.328: e/androidruntime(21541): fatal exception: main 02-16 08:48:43.328: e/androidruntime(21541): java.lang.nullpointerexception 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.app.backstackrecord.doaddop(backstackrecord.java:394) 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.app.backstackrecord.add(backstackrecord.java:389) 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.app.fragmentpageradapter.instantiateitem(fragmentpageradapter.java:99) 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.view.viewpager.addnewitem(viewpager.java:801) 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.view.viewpager.populate(viewpager.java:992) 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.view.viewpager.populate(viewpager.java:881) 02-16 08:48:43.328: e/androidruntime(21541): @ android.support.v4.view.viewpager$3.run(viewpager.java:237) 02-16 08:48:43.328: e/androidruntime(21541): @ android.os.handler.handlecallback(handler.java:605) 02-16 08:48:43.328: e/androidruntime(21541): @ android.os.handler.dispatchmessage(handler.java:92) 02-16 08:48:43.328: e/androidruntime(21541): @ android.os.looper.loop(looper.java:137) 02-16 08:48:43.328: e/androidruntime(21541): @ android.app.activitythread.main(activitythread.java:4575) 02-16 08:48:43.328: e/androidruntime(21541): @ java.lang.reflect.method.invokenative(native method) 02-16 08:48:43.328: e/androidruntime(21541): @ java.lang.reflect.method.invoke(method.java:511) 02-16 08:48:43.328: e/androidruntime(21541): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:789) 02-16 08:48:43.328: e/androidruntime(21541): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:556) 02-16 08:48:43.328: e/androidruntime(21541): @ dalvik.system.nativestart.main(native method)

please solve problem.

most likely, default statement returning null , tries add together null fragment.. , fails... know missing case 2 switch statement.. on purpose? if you, set break

switch(i){

and check value of i... , see if either, 0, 1 or 3... otherwise app crash becuz returning null.

android navigation

No comments:

Post a Comment