java - What is wrong with these static getter & setter methods - Android? -
i'm befuddled tiny problem in android code. getters , setters created in custom class (i.e. 'resultsroominfocustrlyt') give me following 'java nullpointerexception':
05-31 13:37:13.222 29262-29262/com.whitsoft.stan e/androidruntime﹕ fatal exception: main java.lang.nullpointerexception @ com.whitsoft.stan.mods.resultsroominfocustrlyt.setsingleroomsnumbertextvalue(resultsroominfocustrlyt.java:61) @ com.whitsoft.stan.utils.datafixer.updaterelevantviewswithselecteddata(datafixer.java:48) @ com.whitsoft.stan.mods.stanlistfragment.checkifthelistadapterdatahaschanged(stanlistfragment.java:98) @ com.whitsoft.stan.mods.stanlistfragment.onactivitycreated(stanlistfragment.java:49) @ android.app.fragment.performactivitycreated(fragment.java:1707) @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:921) @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1075) @ android.app.backstackrecord.run(backstackrecord.java:682) @ android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1455) @ android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:441) @ android.os.handler.handlecallback(handler.java:730) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5493) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1209) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1025) @ dalvik.system.nativestart.main(native method)
here custom class ('resultsroominfocustrlyt') getters & setters implemented:
public class resultsroominfocustrlyt extends relativelayout { layoutinflater staninflater; private static textview singleroomsnumbertv, singleroomsdesctv, viproomsnumbertv, viproomsdesctv; public resultsroominfocustrlyt(context context) { super(context); staninflater = layoutinflater.from(context); initializeandlayoutchildren(); } public resultsroominfocustrlyt(context context, attributeset attrs) { super(context, attrs); staninflater = layoutinflater.from(context); initializeandlayoutchildren(); } public resultsroominfocustrlyt(context context, attributeset attrs, int defstyleattr) { super(context, attrs, defstyleattr); staninflater = layoutinflater.from(context); initializeandlayoutchildren(); } private void initializeandlayoutchildren() { staninflater.inflate(r.layout.cust_rlyt_results_room_info, this, true); singleroomsnumbertv = (textview) findviewbyid(r.id.stan_single_rooms_number_tv); singleroomsdesctv = (textview) findviewbyid(r.id.stan_single_rooms_description_tv); viproomsnumbertv = (textview) findviewbyid(r.id.stan_vip_rooms_number_tv); viproomsdesctv = (textview) findviewbyid(r.id.stan_vip_rooms_description_tv); } public static string getsingleroomsnumbertextvalue() { return singleroomsnumbertv.gettext().tostring(); } public static void setsingleroomsnumbertextvalue(string singleroomsnumbertext) { singleroomsnumbertv.settext(singleroomsnumbertext); } public static void setviproomsnumbertextvalue (string viproomsnumbertext) { viproomsnumbertv.settext(viproomsnumbertext); } public static string getviproomsdesctextvalue () { return viproomsdesctv.gettext().tostring(); } public static void setviproomsdesctextvalue (string viproomsdesctext) { viproomsdesctv.settext(viproomsdesctext); } }
...as can see love using static getters , setters gives me easy access required views single line of code. odd thing error getting @ runtime have 2 other classes 1 use same setup - , classes work fine (update data required). however, when class's setters called following calls fail execute:
resultsroominfocustrlyt.setsingleroomsnumbertextvalue(singleroomsnumberinfo); resultsroominfocustrlyt.setsingleroomsdesctextvalue(singleroomsdescinfo); resultsroominfocustrlyt.setviproomsnumbertextvalue(viproomsnumberinfo); resultsroominfocustrlyt.setviproomsdesctextvalue(viproomsdescinfo);
any appreciated. thanks. shore-t.
well problem trying set texts of null
text views. example, following line:
resultsroominfocustrlyt.setsingleroomsnumbertextvalue(singleroomsnumberinfo);
tries following:
singleroomsnumbertv.settext(singleroomsnumbertext);
but singleroomsnumbertv? assigned? need call:
new resultsroominfocustrlyt(this);
from activity initialize static textviews.
Comments
Post a Comment