Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

J2ME Error

  • 28-04-2009 12: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,088 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