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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
simon_hain
Posts: 14,061
Registered: ‎07-29-2008
My Carrier: O2 Germany

HomeScreen.updateIcon throws IllegalArgumentException when used in static context

In my apps construtor and on other places i use the following code to update the applications icon and set a
rollover icon.

 

 

public static void changeHomeScreenIcon(boolean unreadItems) {
		if (unreadItems) {
			HomeScreen.updateIcon(BitmapProvider.START_STAR, 0);
			HomeScreen.setRolloverIcon(BitmapProvider.START_STAR_MO, 0);
		} else {
			HomeScreen.updateIcon(BitmapProvider.START, 0);
			HomeScreen.setRolloverIcon(BitmapProvider.START_MO, 0);
		}
	}

 

On startup (app is an autostart app) i get an illegal argument exception.

When I use the same method while the software is running everything works fine.

Any ideas?

 

:

 

----------------------------------------------------------
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
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Carrier: various

Re: HomeScreen.updateIcon throws IllegalArgumentException when used in static context

Are you checking ApplicationManager.getApplicationManager.inStartup() before proceeding with the constructor?

 

I'm not sure you can do that waiting right there in the constructor code, but if you start an initialization Thread and do all the necessary things there, you can certainly loop and wait for that flag to become false before doing anything else.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
Orzech
Posts: 45
Registered: ‎06-23-2010

Re: HomeScreen.updateIcon throws IllegalArgumentException when used in static context

[ Edited ]

AFAIR,

invokeLater(new Runnable() {
	public void run() {
		net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon);
	}
});

solved problem with this exception for me, so you can try it too, however, I do not call it when inStartup. When in startup, you can just register your app as a SystemListener and do initialization in powerUp method implementation.

 

Regards,
Piotr
Please use plain text.
Developer
simon_hain
Posts: 14,061
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: HomeScreen.updateIcon throws IllegalArgumentException when used in static context

 

yes, i check the startup with this code

 

while (app.inStartup()) {
	try {
		Thread.sleep(400);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}

 

 

(i am aware of the "register a listener"-approach but didn't think it necessary to change this).

 

@Orzech: I cannot use invokelater in a static context.

if i am not able to solve the problem i may be able to refactor it this way.

 

In fact, on a real device, it is not a problem, it occurs only on the simulator (forgot to mention this on the first post), if i click "continue" 4 times in the debugger everything works correctly (but the rollover icon is only set on a later call, of course).

----------------------------------------------------------
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
Please use plain text.
Regular Contributor
ManikandanP
Posts: 77
Registered: ‎09-19-2008
My Carrier: Airtel India

Re: HomeScreen.updateIcon throws IllegalArgumentException when used in static context

Hi Simon,

 

Me too updating my application icon and it is static function. I did not face such issue on any OS version. Are you facing this issue on all OS versions?

 

Note, I was getting error "module with handle[] and index[] has no entry point" when attempt made to updateIcon while device boot. (I am not sure whether you are having requirement to update app icon at the device boot up). I just fixed up by trying N attempts with delay temporarily.

Thanks!

Please use plain text.
Developer
Orzech
Posts: 45
Registered: ‎06-23-2010

Re: HomeScreen.updateIcon throws IllegalArgumentException when used in static context

[ Edited ]

Sorry, I thought it is possible to call Application.getApplication().invokeLater in a static context (shame on me, because one needs to have application's instance created to make this working, obviously). SystemListener approach works perfectly for me on both device and simulator, so unfortunately nothing more comes to my mind at this moment. Good luck!

 

Regards,

Piotr

Please use plain text.
Developer
simon_hain
Posts: 14,061
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: HomeScreen.updateIcon throws IllegalArgumentException when used in static context

I have moved the startup code into a static context, get the same error now only with the dispatchinvokelater in front.

 

notable is that i see this error only when hot-swapping the simulator (i should know better than not to include all info in the first post, but was on a (boring) conf call...)

 

according to the docs an illegal argument exception means that the entry point is not found. it's just strange that it works some time later. maybe it is an unsolvable sideeffect of the hot swap.

----------------------------------------------------------
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
Please use plain text.