android - passing context to fragment -


well doing small android project involving fragments.. log cat showing null pointer exception context value null..

this code

public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {      view rootview = inflater.inflate(r.layout.syllabusselection, container, false);     main(rootview);     return rootview; } public void main(view rootview)  {      textview textyear,textsubject,textschema,textpowered ;         final context context = getactivity();         typeface roboto = typeface.createfromasset(context.getassets(), "fonts/roboto/roboto-light.ttf");         typeface nexa = typeface.createfromasset(context.getassets(),"fonts/nexa/nexa_light.ttf");//nexa_light.ttf nexa_bold.ttf           textsubject = (textview)rootview.findviewbyid(r.id.textsubject);         textschema = (textview)rootview.findviewbyid(r.id.textscheme);         textpowered = (textview)rootview.findviewbyid(r.id.textpowered); 

well

final context context = getactivity();

was null changed getactivity() still getting null pointer excewption.. errror??

this log cat

03-10 03:30:06.015: e/androidruntime(1218): fatal exception: main 03-10 03:30:06.015: e/androidruntime(1218): process: info.androidhive.tabsswipe, pid: 1218 03-10 03:30:06.015: e/androidruntime(1218): java.lang.nullpointerexception 03-10 03:30:06.015: e/androidruntime(1218):     @ info.androidhive.tabsswipe.question.main(question.java:63) 03-10 03:30:06.015: e/androidruntime(1218):     @ info.androidhive.tabsswipe.question.oncreateview(question.java:55) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.fragment.performcreateview(fragment.java:1478) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:927) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1460) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:472) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.view.viewpager.populate(viewpager.java:1068) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.view.viewpager.populate(viewpager.java:914) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1436) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.view.measure(view.java:16497) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.widget.framelayout.onmeasure(framelayout.java:310) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.view.measure(view.java:16497) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) 03-10 03:30:06.015: e/androidruntime(1218):     @ com.android.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:327) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.view.measure(view.java:16497) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.widget.framelayout.onmeasure(framelayout.java:310) 03-10 03:30:06.015: e/androidruntime(1218):     @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2291) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.view.measure(view.java:16497) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1916) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1113) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1295) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1000) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5670) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.choreographer$callbackrecord.run(choreographer.java:761) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.choreographer.docallbacks(choreographer.java:574) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.choreographer.doframe(choreographer.java:544) 03-10 03:30:06.015: e/androidruntime(1218):     @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) 

move invocation of main onactivitycreated of fragment. means should move rootview.findviewbyid calls oncreateview , retain typeface calls in main.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -