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
Posts: 83
Registered: ‎02-03-2009
My Device: 9500/9520/9800/9810
My Carrier: TMobile

ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

Today I had to realize, that you can only use the Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES  from an UIApplication class not from juat an Application Smiley Surprised

That's cause (for what ever reason) the Constructor of the EmailEditorSceen class (in my Debugger it's said in Line90) makes use of the Method UiApplication.getUiApplication() -> and of course this will end in an ClassCastException in the Moment you are try to invoke the Message App just from an normal Application class (and not an UIApplication)...

My initial thought (for a Worrkarround) was to launch from my Application a new UIApplication that will then invoking the MessageApp... but looks like I can't use somthing like that:

 

 

in my Application:

new MailLauncher(theMessage).enterEventDispatcher();

and as MailLauncher:

private static class MailLauncher extends UiApplication {
	private Message m;
	
	private MailLauncher(Message m){
		super();
		this.m = m;
		show();
	}
	
	public void show(){
		try{
			Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(m));
			System.exit(0);							
		}catch(Throwable t){
			t.printStackTrace();
		}
	}
}

 any alternative suggestions? - Chaning the initial Application to an UIApplication is not an option at all.

 

[FileScout] | [iMazing] | [GPSLogger II] | [Iconify] | [TOMPlayer]
Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

My think MessageArguments evolved from different OS versions. You can develop and compile app under one OS version and run it under another. This can cause ClassCastException.

Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

Hi Emac,

 

can you check which type of Message are you using? it should be net.rim.blackberry.api.mail.Message and not other message.

 

just double check. Smiley Happy 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

yes, it is a constraint. you can use a second UiApplication, but you would have to run it using applicationmanager.

another option would be to have it running in the background all the time, overwrite acceptsForeground() to disable any user interaction and use runtimestore or a global event to command it to open the message app.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎02-03-2009
My Device: 9500/9520/9800/9810
My Carrier: TMobile

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

[ Edited ]

 


simon_hain wrote:

yes, it is a constraint. you can use a second UiApplication, but you would have to run it using applicationmanager.


 

 

Thanks Simon - I already considder this appropach - Might be I have understood something totally wrong, but in oder to Start a "new" Application I need an ApplicationDescriptor pointing to a main class of an UiApplication...

 

I tried to use a single main and depending on the args[] I am createing a UIApplication... but for some reason, this UIApplication does not show up - I think it have to do with the fact, that the main method is in an Application class and for what ever reasons I am stuck with that application class... and there seams to be no way out for me...

 

So my next though was, that I simply need another class (extening UIApplication this time) containing a main method... but then I am not aware, that there is a way to create a AppDescr with "MySecondMainClassNameThatExtendsUiApplication" and Parameters...

 

Also creating an Additonal AppEntryPoint (in my IDE) will not help, since this is again just an entryPoint for myApplication Class main method (and I do not see a way to specify a different class containing a "main")... So I think I would need to create a total different cod_module (containing that UiApplication + it's ApplicationDescriptor)...

 

Then IMHO I run into the problem, that I would like to provide two modules each with own ApplicationDescriptors for each of the CodModules in a single OTA installation...  -> and I am not aware, that this is something that can be done...

 

BTW: If I am sounding confused - then this is simply cause I AM confused ;-)

[FileScout] | [iMazing] | [GPSLogger II] | [Iconify] | [TOMPlayer]
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

You don't need a second main, you can just make a seperate class that extends UiApplication and create it from a different entry point. I have an application that uses both a background Application and a UiApplication. Which one is started depends on how you the "App" is started.

Developer
Posts: 83
Registered: ‎02-03-2009
My Device: 9500/9520/9800/9810
My Carrier: TMobile

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

 


CMY wrote:

You don't need a second main, you can just make a seperate class that extends UiApplication and create it from a different entry point...


 

 

Just for me to clearify... you have something like this?

 

 

public static void main(String[] args) {
	if(args != null && args.length > 0){
		for (int i = 0; i<args.length; i++) {
			if(args[i].equalsIgnoreCase("app")){
				new MyApp().enterEventDispatcher();
			}else if(args[i].toLowerCase().startsWith("gui")){
				new MyUiApplikation().enterEventDispatcher();
			}
		}
	}
}

So once I use the "gui" as additional AppDecriptor parameter then the UIApplication will be instanciated... and if it's just "app", then the normal application (as it was before) will be launched?

 

Actually for sure I did that, but what ever i will do inside the MyUiApplication constructor, pushing screens or what ever - actually nothing happens on the device :-| ... I can make use of the UiApplication.getUiApplication() Method without any class cast exceptions - but I found no way to push from the MyUiApplication any kind of screen - no matter if that was done by using invokeLater or anything like that... I thought the reason for that behaviour is, that my main class is extending Application... but that might be the total wrong direction...

 

[FileScout] | [iMazing] | [GPSLogger II] | [Iconify] | [TOMPlayer]
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

I think I had the same issue before and resolved it by synchronizing on the event thread to be able to do ui processing. But, alternately you could just as easy make your main class derive from UiApplication and make the second class the Application to be auto-started.

Developer
Posts: 83
Registered: ‎02-03-2009
My Device: 9500/9520/9800/9810
My Carrier: TMobile

Re: ClassCastException when using Invoke.APP_TYPE_MESSAGES... from an Application

Thanks - finally I got it working...  sync was probably the key - and now finally my UiApp can fire up the MessageApp... and once the MessageApp is running I am not allowed to use System.exit(0) in my UIApplication (since that will take down the MessageScreen as well) - now I use

 

public void deactivate(){
    System.exit(0);
}

 

in my UIApp in order to ensure that it will be terminated once the MessageComposer will be closed...

[FileScout] | [iMazing] | [GPSLogger II] | [Iconify] | [TOMPlayer]