It's not a secret anymore!*
The moose likes Java Micro Edition and the fly likes ItemStateListener and itemStateChanged() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "ItemStateListener and itemStateChanged()" Watch "ItemStateListener and itemStateChanged()" New topic

ItemStateListener and itemStateChanged()

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I recently bought the book Core J2ME Technology and am working through the examples. I'm having a problem with the ItemStateListner stuff. I understand that the MIDP specification says that itemStateChanged() doesn't have to be called every time a change occurs. However, I don't understand why this is.
In fact, in the first example for ItemState events on page 117, the itemStateChanged() method is never called. I can change the DateField item as many times as I want, and it still isn't called.
I thought this might just be a fluke, but I came to a similar example for a snooze MIDlet. The same thing happens: when the date/time is changed the event never fires.
What is going on here? What's the point of an event handler that is never called? I'm very confused about this issue.
I know I should probably post some code, but I think that might be a bit premature at this point. If you have the book, the examples are on page 117 ( and page 132 (
I am developing with the Linux version of MIDP. Perhaps it has to do with this specific implementation?
Any comments will be greatly appreciated.

Java API Documentation
The Java Tutorial
john muchow
Ranch Hand

Joined: Mar 24, 2001
Posts: 49
>In fact, in the first example for ItemState
>events on page 117, the itemStateChanged()
>method is never called. I can change the
>DateField item as many times as I want, and it
>still isn't called.
This must be an error with the implementation.
If you look at page 119, you will see the screen shot that I captured (right most figure), showing the result once the event is executed.
What implementation are you using? Feel free to forward the examples to the developers to show the problem.
John Muchow
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Sorry, I forgot to mention the developer. I'm using Sun's implementation for Linux. I guess I assumed that their own implementation would handle this correctly. I thought I'd done something wrong. Maybe I just need to go over the code to make sure it is the exact same as the listing in your book...
john muchow
Ranch Hand

Joined: Mar 24, 2001
Posts: 49
Hi Layne,
When you have a chance, send me the code you have written. Although I don't have the Linux install, I will run the code on my machine and see if it runs.
If it does, we can decide how to proceed from there.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Will do. I also downloaded the source code from your site so I can do a diff with the code I typed in. Usually I avoid downloading source code because typing the examples usually helps me learn the concepts better.
Well, thank you for your time. I sure would like to figure out what the problem is...
David Carlson

Joined: Dec 14, 2004
Posts: 1
Now it's 12/14/2004 I'm having the same itemStateListener issues. What was the solution?
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Steps :1

implements the itemStateListener in class

Step :2

add method like public void itemStatechanged(Item item){

step :3

add itemStateListener


Thank You<br />Edward
Andrea Cacciarru

Joined: Feb 09, 2006
Posts: 2
I have the same problem too. If I try Muchow's example in my Sun wireless toolkit everything works fine, but if I try Snooze example in my LG U8180 mobile, the itemStateChanged don't works! Maybe can it depend by the LG's JVM implementation?
It is sorta covered in the JavaRanch Style Guide.
subject: ItemStateListener and itemStateChanged()
Similar Threads
jsessionid always appended to urls on first request
whaat is the point of this?
Getting NullPointerExceptionError when working with the CheckboxGroup
Objectives for the SCMAD exam are here!!
itemstatechanged event on Jcombobox