java - if and else statement both executed within onclicklistener for linearlayout -


i have onclicklistener linearlayout:

   linearlayout closedbets = (linearlayout) findviewbyid (r.id.closedbetslayout);     closedbets.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             textview closedtxt = (textview) findviewbyid(r.id.settledbetstxtview);             closedtxt.settextcolor(color.parsecolor("#09ad21"));             textview openbetstxt = (textview) findviewbyid(r.id.openbetstxtview);             openbetstxt.settextcolor(color.parsecolor("#b4b5ae"));             listwriter = getlistwriter();             if (listwriter.size() ==0) {                 log.d("empty listwriter","empty");                 textview emptybet = (textview) findviewbyid(r.id.nobetstxtbox);                 emptybet.settext("none of bets have been settled yet.");                 emptybet.setvisibility(view.visible);             }             else {                 populatelist();             }         }     }); 

the issue when listwriter empty , log executed, reason populatelist(); method gets executed , nullpointerexception in adapter used populate list since listwriter empty.

logcat

06-29 18:51:08.492  28394-28394/com.example.albert.bettertipapp d/empty listwriter﹕ empty 06-29 18:51:08.512  28394-28394/com.example.albert.bettertipapp d/androidruntime﹕ shutting down vm 06-29 18:51:08.512  28394-28394/com.example.albert.bettertipapp w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x4172cda0) 06-29 18:51:08.532  28394-28394/com.example.albert.bettertipapp e/androidruntime﹕ fatal exception: main     process: com.example.albert.bettertipapp, pid: 28394     java.lang.indexoutofboundsexception: invalid index 0, size 0             @ java.util.arraylist.throwindexoutofboundsexception(arraylist.java:255)             @ java.util.arraylist.get(arraylist.java:308)             @ com.example.albert.betterapp.displayallbets$mylistadapter.getview(displayallbets.java:764)             @ android.widget.abslistview.obtainview(abslistview.java:2733)             @ android.widget.listview.measureheightofchildren(listview.java:1274)             @ android.widget.listview.onmeasure(listview.java:1186)             @ android.view.view.measure(view.java:17396)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5365)             @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1410)             @ android.widget.linearlayout.measurevertical(linearlayout.java:695)             @ android.widget.linearlayout.onmeasure(linearlayout.java:588)             @ android.view.view.measure(view.java:17396)             @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:719)             @ android.widget.relativelayout.onmeasure(relativelayout.java:455)             @ android.view.view.measure(view.java:17396)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5365)             @ android.widget.framelayout.onmeasure(framelayout.java:310)             @ android.view.view.measure(view.java:17396)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5365)             @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1410)             @ android.widget.linearlayout.measurevertical(linearlayout.java:695)             @ android.widget.linearlayout.onmeasure(linearlayout.java:588)             @ android.view.view.measure(view.java:17396)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5365)             @ android.widget.framelayout.onmeasure(framelayout.java:310)             @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2505)             @ android.view.view.measure(view.java:17396)             @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2175)             @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1316)             @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1513)             @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1200)             @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6401)             @ android.view.choreographer$callbackrecord.run(choreographer.java:803)             @ android.view.choreographer.docallbacks(choreographer.java:603)             @ android.view.choreographer.doframe(choreographer.java:573)             @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:789)             @ android.os.handler.handlecallback(handler.java:733)             @ android.os.handler.dispatchmessage(handler.java:95)             @ android.os.looper.loop(looper.java:157)             @ android.app.activitythread.main(activitythread.java:5335)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1265)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1081)             @ dalvik.system.nativestart.main(native method) 


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -