×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    9

    IllegalStateException

    i am new to j2me environment and i am developing an application for nokia s40 devices. am using gesture and frame animator api, when ever i try to flicking a page i get an
    exception, "illegalstateexception".

    can anyone please explain me, why am i getting this exception. reply soon.

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    376

    Re: IllegalStateException

    Post the code so we can rectify what exactly error is

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: IllegalStateException

    Probably, you are calling something like getFlickDirection() on a GestureEvent object, without checking that the GestureEvent type is GestureInteractiveZone.GESTURE_FLICK. Check the event type before processing it.

    Graham.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    9

    Re: IllegalStateException

    this is my code for gesture actions. I have four canvas classes. when ever moving from one canvas to another and try to flick a page immediately it shows illegal state exception. am using this code in every canvas. help me to rectify this exception...

    public void gestureAction(Object container,GestureInteractiveZone gestureZone, GestureEvent gestureEvent) throws RuntimeException
    {
    try
    {
    if (container.equals(this)) {
    if (gestureZone.equals(gizCanvas))
    handleGestureCanvas(container, gestureZone, gestureEvent);
    else if (gestureZone.equals(gizRectangle))
    handleGestureRect(container, gestureZone, gestureEvent);
    }
    }
    catch(RuntimeException e)
    {
    e.printStackTrace();
    }

    }

    public void handleGestureCanvas(Object container,GestureInteractiveZone gestureZone, GestureEvent gestureEvent)
    {
    // Which gesture
    switch (gestureEvent.getType()) {
    case GestureInteractiveZone.GESTURE_TAP: {

    Pressed(gestureEvent.getStartX(), gestureEvent.getStartY());
    }
    ;
    break;
    case GestureInteractiveZone.GESTURE_FLICK: {
    rectAnimator.kineticScroll(gestureEvent.getFlickSpeed(),
    FrameAnimator.FRAME_ANIMATOR_FREE_ANGLE,
    FrameAnimator.FRAME_ANIMATOR_FRICTION_MEDIUM,
    gestureEvent.getFlickDirection());
    }
    ;
    break;
    default:
    }

    }

    public void handleGestureRect(Object container,GestureInteractiveZone gestureZone, GestureEvent gestureEvent)
    {
    // Which gesture
    switch (gestureEvent.getType()) {
    case GestureInteractiveZone.GESTURE_DRAG: {
    // Adds up the drag distances since last call to animate()
    dragCounterX += gestureEvent.getDragDistanceX();
    dragCounterY += gestureEvent.getDragDistanceY();

    int newX = (dragCounterX + myRectPosX);
    int newY = (dragCounterY + myRectPosY);
    rectAnimator.drag(newX, newY);
    }
    ;
    break;
    default:
    }

    }

    public void animate(FrameAnimator animator, int x, int y, short delta,short deltaX, short deltaY, boolean lastFrame)
    {

    // Update paint with the new coordinates for the rectangle
    setMyRectPosX(x);
    setMyRectPosY(y);
    // Update the Gesture Interactive Zone for the rectangle
    gizRectangle.setRectangle(myRectPosX, myRectPosY, myRectWidth,myRectHeight);
    // Update paint with the new coordinates for the interactive zone
    myGestureZonePosX = myRectPosX;
    myGestureZonePosY = myRectPosY;
    // Refresh screen
    repaint();

    // If last frame of the animation
    if (lastFrame) {
    // Reset animation settings
    rectAnimator.unregister();
    rectAnimator.register(myRectPosX, myRectPosY, maxFps, maxPps, this);
    resetDragCounters();
    }

    }


    i am getting following error:


    java.lang.IllegalStateException
    at com.nokia.mid.impl.isa.ui.frameanimator.FrameAnimatorImpl.kineticScroll(+21)
    at com.nokia.mid.ui.frameanimator.FrameAnimator.kineticScroll(+12)
    at ShopCanvas.handleGestureCanvas(ShopCanvas.java:636)
    at ShopCanvas.gestureAction(ShopCanvas.java:609)
    at javax.microedition.lcdui.CanvasTouchHandler.consumeGestureEvent(+120)
    at javax.microedition.lcdui.TouchHandlerImpl.consumeTouchUIEvent(+102)
    at javax.microedition.lcdui.Display$DisplayAccessor.consumeEvent(+199)
    at com.nokia.mid.impl.isa.ui.EventDispatcher.run(+51)

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: IllegalStateException

    OK... look at where the error comes from....

    Quote Originally Posted by madhu23 View Post
    at com.nokia.mid.ui.frameanimator.FrameAnimator.kineticScroll(+12)
    FrameAnimator.kineticScroll().

    Take a look at the JavaDocs for this method:

    Throws:
    java.lang.IllegalStateException - if this FrameAnimator has not been registered.
    Graham.

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    376

    Re: IllegalStateException

    Javadoc for this can be found here http://library.forum.nokia.com/index...eAnimator.html

  7. #7
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Re: IllegalStateException

    Hi,

    I was using the gesture and the frame animator api too, and I used to get the IllegalStateException too. I don´t know if your case is like mine, but, do you create multiple screens (or multiple copies of the same screen) that use the gesture and frame animator? I noticed that after 5 screens the exception started to show up, and determinded (empyrically) that the maximum possible number of FrameAnimators registered at the same time was around 5. After that the animators couldn't get registered, and the IllegalStateException appeared when trying to use them (when they were, in fact, in an illegal state).

    I added some code to "un-register" them when the screens were destroyed, and the problem is gone now. So, I registered the animator once when the screen/canvas was created, and unregistered it when the screen/canvas was destroyed. Maybe you have multiple registrations at some point?

    I hope this help you with your problem.

Similar Threads

  1. java.lang.IllegalStateException
    By anirban_5683 in forum Tools and SDK Feedback (Closed)
    Replies: 1
    Last Post: 2006-12-25, 22:21
  2. IllegalStateException
    By metajohn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2005-12-02, 11:42
  3. IllegalStateException
    By Paul_Eakins in forum Mobile Java General
    Replies: 0
    Last Post: 2003-07-16, 15:13
  4. IllegalStateException
    By tuttas in forum Mobile Java General
    Replies: 0
    Last Post: 2003-05-23, 12:41
  5. IllegalStateException
    By fbayindir in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-05-10, 19:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×