codenameone - SpanButton client property throws NullPointerException -


i trying client property on spanbutton when clicked. throwing nullpointerexception.

i tested same code regular button , works fine. believe there bug there.

here how can recreate issue barebone project:

    form hi = new form("hi world");     button button = new button("button");     button.putclientproperty("id", 100);      spanbutton spanbutton = new spanbutton("spanbutton");     spanbutton.putclientproperty("id", 200);       button.addactionlistener(new actionlistener() {         @override         public void actionperformed(actionevent evt) {             int id = (int) evt.getcomponent().getclientproperty("id");             system.out.println("standard button action listener: id = " + id);         }     });      spanbutton.addactionlistener(new actionlistener() {         @override         public void actionperformed(actionevent evt) {             int id = (int) evt.getcomponent().getclientproperty("id");             system.out.println("span button action listener: id = " + id);         }     });      hi.addcomponent(button);     hi.addcomponent(spanbutton);     hi.show(); 

if click on button, output printed correctly:

standard button action listener: id = 100

if click on spanbutton, nullpointerexception thrown. upon investigation, found out spanbutton getclientproperty("id") returning null.

note: need use spanbutton because of variable size support.

instead of getcomponent() use aptly named getactualcomponent().

the javadocs explain why:

identical actionevent#getcomponent() except fact lead component returned if such lead component available.

this important components such multibutton return underlying button instead.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -