Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

J2ME Error

  • 28-04-2009 01:22AM
    #1
    Registered Users, Registered Users 2 Posts: 269 ✭✭


    I have the following midlet calling a web service and retrieving results however i am getting the following error can anyone help


    java.lang.IllegalMonitorStateException

    
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import ie.travel.webservice.*;
    public class Travel extends MIDlet {
    	 private Display display;
    	    private Command exit;
    	    private Command submit;
    	    private TextBox employeetextbox;
    	    private AdministrationService_Stub admin;
    	    private Form form;
    	    private StringItem stringItem;
    	public Travel() {
    		exit = new Command("Exit",Command.EXIT,0);
            submit = new Command("Submit",Command.OK,1);
            form = new Form("Travel 2.0 Web Services");
            employeetextbox = new TextBox("Employee","",5,0);
            admin= new AdministrationService_Stub();
    	}
    
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    		// TODO Auto-generated method stub
    
    	}
    
    	protected void pauseApp() {
    		// TODO Auto-generated method stub
    
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    		// TODO Auto-generated method stub
    		  display = Display.getDisplay(this);
    	        display.setCurrent(employeetextbox);
    	        
    	       
    	       try{
    	      employeetextbox.setString("2001");
    	      String employee = employeetextbox.getString();
    	      String result=admin.getEmployee(employee);
    	      Alert alert = new Alert("Result",result,null,null);
    		  display.wait(5000);
    	      display.setCurrent(alert);
    	       }
    	       catch(Exception ex){
    	       Alert alert = new Alert("Error","ex"+ex,null,null);
    	       System.out.println(ex);
    	       display.setCurrent(alert);
    	       }
    	}
    
    }
    
    
    
    
    
    


Comments

  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    cyberwit wrote: »
    java.lang.IllegalMonitorStateException

    have you got the trace (for a few lines at least)

    so we can identify which lines causes it?

    change System.out.println(ex);
    to
    ex.printStackTrace(System.err);


  • Moderators, Science, Health & Environment Moderators Posts: 10,093 Mod ✭✭✭✭marco_polo


    You need to own the object lock to call wait () or notify on an object. You can do this by wrapping the call in a synchronized block.

    synchronized (display) {   
          display.wait(5000);   
     }
    

    If all you doing is pausing the thread for 5 seconds you should use a call to Thread.sleep(5000) instead (no need for synchronized block in this case)


Advertisement