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
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

Main Screen Notification Intergration

[ Edited ]

Good day, I have tried using the following code to have a notification image pop up on my main Sceen bar. Unfortunately i keep getting an exception. can some one help me fix this up please?

ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();    

EncodedImage image = EncodedImage.getEncodedImageResource("Indicator.png");

ApplicationIcon icon = new ApplicationIcon( image );

ApplicationIndicator indicator = reg.register( icon, false, true);
//Exception java.lang.IllegalArgumentException
indicator.setIcon(icon); 
indicator.setVisible(true);

 

Please use plain text.
Developer
Dionysus
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900

Re: Main Screen Notification Intergration

If the exception is being thrown where you have put a comment then I can only assume that the "Indicator.png" does not exist in your resources folder or it is named incorrectly.

Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

The Image Does exist and if not it would have given an "I...

The Image Does exist and if not it would have given an "Image not found error", The error is in the line below the, Sorry that was my fault will fix it quickly.

Please use plain text.
Developer
Dionysus
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900

Re: The Image Does exist and if not it would have given an "I...

It will only throw a null pointer if the icon is null at the point of registration. If you add a breakpoint before registering, can you confirm that the icon is not null?

 

If so, could you copy and paste your stacktrace?

Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

Re: The Image Does exist and if not it would have given an "I...

CODE:

public class Screen extends MainScreen { public Screen() { Thread uiUT = new Thread(uiUpdaterThread); uiUT.start(); } private Runnable uiUpdaterThread = new Runnable() { public void run() { while(true) { //Create Fields via JSon System.out.println("Thread Starting"); try{ System.out.println("1"); ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance(); System.out.println("2"); EncodedImage image = EncodedImage.getEncodedImageResource("Alerts.png"); System.out.println("3"); ApplicationIcon icon = new ApplicationIcon( image ); System.out.println("4"); ApplicationIndicator indicator = reg.register( icon, false, true); System.out.println("5"); indicator.setIcon(icon); System.out.println("6"); indicator.setVisible(true); System.out.println("7"); }catch (Exception e){ System.out.println("Thread------------Exception "+e ); e.printStackTrace(); }try{ Thread.sleep(5000); System.out.println(" Thread Sleeping"); }catch (Exception e){ System.out.println("Thread------------Exception "+e ); e.printStackTrace(); } } } } ;
}

 StackTrace :

Thread Starting
[0.0] 1
[0.0] 2
[0.0] 3
[0.0] 4
[0.0] Thread------------Exception java.lang.IllegalArgumentException
[0.0] No stack trace
[0.0] FocusHistory: Focus gained; App NotificationOnHomescreen; Component com.ranworx.Screen
[0.0] AM: Exit net_rim_bb_trust_application_manager(282)
[0.0] ApplicationManagerImpl.processExited : process process switching to background: pid=282
[0.0] Process net_rim_bb_trust_application_manager(282) cleanup started
[0.0] Process net_rim_bb_trust_application_manager(282) cleanup done

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: The Image Does exist and if not it would have given an "I...

without looking at the issue:
this API does not put a notification in a bar of your mainscreen, it adds a notification on the device homescreen.

tracking down a nullpointer is easiest by setting an exception breakpoint in eclipse, choose nullpointer and debug.
----------------------------------------------------------
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.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

Re: The Image Does exist and if not it would have given an "I...

When I change the image name to an image that does not exist:

[0.0] Thread Starting
[0.0] 1
[0.0] 2
[0.0] FocusHistory: Focus gained; App NotificationOnHomescreen; Component com.ranworx.Screen
[0.0] FRIDG: could not find Alerts!.png
[0.0] 3
[0.0] Thread------------Exception java.lang.NullPointerException
[0.0] No stack trace
[0.0] AM: Exit net_rim_bb_trust_application_manager(285)
[0.0] ApplicationManagerImpl.processExited : process process switching to background: pid=285
[0.0] Process net_rim_bb_trust_application_manager(285) cleanup started
[0.0] Process net_rim_bb_trust_application_manager(285) cleanup done

Please use plain text.
Developer
Dionysus
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900

Re: The Image Does exist and if not it would have given an "I...

Firstly, it's an IllegalArgumentException and not a NullPointer.

 

Try changing your register parameter to "true" for iconOnly:

 

ApplicationIndicator indicator = reg.register( icon, true, true);

 

 

Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

Re: The Image Does exist and if not it would have given an "I...

Hi Simon, I meant I want the Notification to display on the home screen. Can you maybe explain to me how to "setting an exception breakpoint in eclipse, choose nullpointer and debug" .

 

I only know how to go "Right Click" and "Toggle Break Point"

Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

Re: The Image Does exist and if not it would have given an "I...

Please use plain text.