Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
H3llGhost
Posts: 79
Registered: ‎02-19-2009
My Device: Not Specified

Uncaught IllegalStateException: No application instance

[ Edited ]

Hello,

 

I know there are a few Messages with the IllegalStateException, but none of them help me.

I want to Invoke the Message Application but I get the named Exception.

 

Here is my main file:

 

 

public class MyApp extends Application
{

	public MyApp() {
		
		//Add MenuItem to the Addressbook-Menu
		ApplicationMenuItemRepository.getInstance().addMenuItem(
				ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST,new MenuItem());
		
	}
	
	public static void main(String[] args) {
		
	     if ( args != null && args.length > 0 && "start".equals(args[0]) ){
	          if (args.length >= 3) {
	        	  CopyContact c = new CopyContact(args[1], args[2]);
	        	  c.process();
	          }
	     } else {	
	 		long ID = 0x9b81c33f1704bd12L;
	 		
	 		//Don't launch twice or more times
	 		RuntimeStore appReg = RuntimeStore.getRuntimeStore();
	 		synchronized(appReg){
	 		   if (appReg.get(ID) == null) {
	 				MyApp app = new MyApp();
	 				app.enterEventDispatcher();
	 				appReg.put(ID, app);
	 		   }
	 		   appReg.waitFor(ID);
	 		}
	     }
	}

}

 

 

And the class where I call the Invoke is here:

 

public class CopyContact {
	
	private String id, name;
	
	public CopyContact(String id, String name) {
		this.id = id;
		this.name = name;
	}
	
	public void process() {
			this.processContactSending();
	}

	private void processContactSending() throws IOException, PIMException {
		MessageConnection messageCon = null;
		messageCon = (MessageConnection) Connector.open("sms://");

		TextMessage sms = (TextMessage) messageCon
				.newMessage(MessageConnection.TEXT_MESSAGE);
		sms.setPayloadText("blub");

		Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
				new MessageArguments(sms));
		messageCon.close();
	}

}

 

 

I tried to surrend the Invoke with synchrozied (Application.getEventLock()) but it fails.

 

Perhaps there are some ideas from you. I will be happy. :smileyhappy:

Developer
dpreussler
Posts: 212
Registered: ‎07-18-2008
My Device: Storm 9550

Re: Uncaught IllegalStateException: No application instance

Do you know where exactly the exception occurs?

 

Just some ideas:

doing the put after entereventdispatcher seems to be a bad idea because the method blocks and never returns!

 

I think the exception wants to tell that there is no application registered with Entereventdispatcher. Are you sure he reaches the code where you create your app?

If your problem was solved, please mark answer as "Accepted solution"
If your want to thank, click the "kudo" symbol
___________
visit me: http://mobilejavadevelopment.blogspot.com/
visit the Berlin BlackBerry Developer Group: http://berlinblackberrydevelopers.blogspot.com/
Developer
H3llGhost
Posts: 79
Registered: ‎02-19-2009
My Device: Not Specified

Re: Uncaught IllegalStateException: No application instance

Here the Exception occurs:

Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,new MessageArguments(sms));

 

In my test it works so, but it think the other way around isn't problematicly.

 

Must I load my Application from the RuntimeStore?

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Uncaught IllegalStateException: No application instance

just make an instance of your app. You may want to invokelater and enter  dispatch and then do your

stuff from your own run method.

Developer
H3llGhost
Posts: 79
Registered: ‎02-19-2009
My Device: Not Specified

Re: Uncaught IllegalStateException: No application instance

[ Edited ]

But when I make another instance of my app I have the MenuItem more than one time.

 

EDIT:
I have edited the Construktor of MyApp, and then I think there aren't more than one MenuItems.

How can I use invokeLater?

 

EDIT²:

 

 

				MyApp m = new MyApp(false);
CopyContact c = new CopyContact(args[1], args[2]);
c.process();
m.enterEventDispatcher();

 

With that code I get a ClassCastException. I can't understand ...

 

When I replace the second parameter of the invokeApplication with null it works.

But don't when I give the MessageArguments with it ...

Any ideas?

Developer
H3llGhost
Posts: 79
Registered: ‎02-19-2009
My Device: Not Specified

Re: Uncaught IllegalStateException: No application instance

Can anyone explain me why that code doesn't work any longer?!

 

 

		MessageConnection messageCon = null;
		messageCon = (MessageConnection) Connector.open("sms://");

		TextMessage sms = (TextMessage) messageCon
				.newMessage(MessageConnection.TEXT_MESSAGE);
		sms.setPayloadText("test");

		Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
				new MessageArguments(sms));
		messageCon.close();

 

It occurs a ClassCastException ...

 

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Uncaught IllegalStateException: No application instance

[ Edited ]

Whenever you get class cast, getClass().getName() on thing you have and see how it fails to

related to what you want. Also, I'm not entirely sure which app instance was at issue here.

Illegal state usually refers to the lack of an existing app from which you can get some thing

but it looks like you are trying to invoke some other app which could fail do to

a failure to exist. Offhand, combined with fact you tried this stuff [ed, prior to not "in" ]  ctor, I'd think the former

could be an issue but I haven't gone bak through all this stuff.

 

Developer
H3llGhost
Posts: 79
Registered: ‎02-19-2009
My Device: Not Specified

Re: Uncaught IllegalStateException: No application instance

I'm sorry but I can't understand all from you, caused of I am not so well in English.

 

Why works

 

Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,null);

 

but following not 

 

Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(sms));

 

Okay there is a Cast, but when I use directly it worked.