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
New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch
My Carrier: Vodafone

Re: How to display images on the main screen UI from a background thread

Hi Peter

 

it throws some compiler errors when i use "this" as arguments for the pop and pushScreen methods. therefore I used the variable "s" in there and it threw a nullpointer exception. have a look at the snippet please

 

class MyBitmapField extends BitmapField {

        public void layout(int width, int height) {

            super.layout(width, height);

        }

        public void paint(Graphics g) {

            super.paint(g);

        }


        public void setBitmap(Bitmap newBitmap) {
            
            Screen s = this.getScreen();

            if ( s != UiApplication.getUiApplication().getActiveScreen() ) {

                if ( s.isDisplayed()) {

                    UiApplication.getUiApplication().popScreen(s);

                }

                UiApplication.getUiApplication().pushScreen(s);

            }
            
            super.setBitmap(newBitmap);

        }

        public void onExposed() {

            super.onExposed();

        }
    }   

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to display images on the main screen UI from a background thread

Thanks for fixing my code, you are correct to change to "s";

 

Did you figure out what was null?

 

If not, then change the code as follows.

 

        public void setBitmap(Bitmap newBitmap) {
            
            Screen s = this.getScreen();

if ( s == null ) {

Dialog.alert("Field is not a Screen");

} else {


            if ( s != UiApplication.getUiApplication().getActiveScreen() ) {

                if ( s.isDisplayed()) {

                    UiApplication.getUiApplication().popScreen(s);

                }

                UiApplication.getUiApplication().pushScreen(s);

            }
}

            
            super.setBitmap(newBitmap);

        }

 

Run this and if this doesn't detect the null, try to figure out what is null.  You should get an Exception which the debugger will report but you may have to go back a bit in the stack trace to find the method in your code that has started the chain leading to the NPE. 

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch
My Carrier: Vodafone

Re: How to display images on the main screen UI from a background thread

[ Edited ]

Hi peter. I tried the code u gave me it throws a runtime exception saying trying to pushModalScreen from a nonevent thread. and I found out what threw the NPE before. it was  Screen s = this.getScreen(); returns null. Im like confused right now!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to display images on the main screen UI from a background thread

OK, this is probably my mistake.

 

You may recall that in this Post:

http://supportforums.blackberry.com/t5/Java-Development/How-to-display-images-on-the-main-screen-UI-...

 

I asked you to put some debugging code in which checked that camView was a screen.  In that code, you told me that the Dialog you were seeing was

"its not the currently active screen".

 

Now we have put similar code inside the bmpStream, and it is failing.  What this suggests is that setBitmap is called from somewhere else, so let us pull the code out of the setBitmap in your class, and put something equivalent in the background processing.  IN other words, replace the debugging code that I got you to put in in the Post referenced above, with the new code that will bring to the foreground the screen that bmpStream is owned by.  As I am doing something else atm, I am hoping that you can figure out what it was going and create this update yourself. 

 

Good luck. 

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch
My Carrier: Vodafone

Re: How to display images on the main screen UI from a background thread

HI peter thanks for your help like you said there are two screens and i used some logs and they have two completely different screen ids. How ca that be because this is the only camView reference im creating which is passed to the background thread. Il keep debugging on this matter

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch
My Carrier: Vodafone

Re: How to display images on the main screen UI from a background thread

Hi peter i think i found the problem regarding the update. in my application Im displaying a login Screen which is a popupScreen where my main Screen would be at the background.

 

this is how it happens at first im pushing my mainscreen and then my popupScreen on top of it. once the user successfuly signs in the popup Closes and the bitmapField on the mainScreen starts getting images. Im telling this because as I told you before setBitmap worked both for us using static images so I removed the popupSCreen and I tried updating the screen with images using the setBitmap method and it started workign perfectly.

 

So my guess is that it is something to do with the way i close the popupScreen or something. do you have any idea about this

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to display images on the main screen UI from a background thread

When you close you PopupScreen, do you crate a new 'camView' like screen?  That would be the easy way to have this problem. 

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch
My Carrier: Vodafone

Re: How to display images on the main screen UI from a background thread

No i Dont peter for ur info this is exactlyw hat im doing,

 

btnOk.setChangeListener(new FieldChangeListener() {

                public void fieldChanged(Field field, int context)
                {
                    // TODO Auto-generated method stub
                    try
                    {
                        if(field == btnOk)
                        {
                            phoneNumber = efPhoneNumber.getText().toString();
                            System.out.println("User Entered Mobile Number: " + phoneNumber);
                            pinNumber = efPinNumber.getText().toString();
                            System.out.println("User Entered PIN Number: " + pinNumber);

                            LiveGuardDBAdapter lvg = new LiveGuardDBAdapter();

                            if(!lvg.TableExists())
                            {
                                lvg.CreateTable();
                                lvg.InsertMobileNumber(phoneNumber);
                            }
                            else
                            {
                                String mobile = lvg.getMobileNumber();
                                if(!mobile.equals(phoneNumber))
                                {
                                    lvg.UpdateMobileNumber(phoneNumber);
                                }
                            }                

                            System.out.println("We should close");

                            signInButtonClicked(phoneNumber, pinNumber);    


                            close();

                            System.out.println("Active Screen: " + UiApplication.getUiApplication().getActiveScreen());                          
                            System.out.println("Active Screen: " + UiApplication.getUiApplication().getActiveScreen());
                        }
                    }catch (IllegalArgumentException e) {
                        // TODO: handle exception
                        System.out.println("Popup exception while signingIn " +e.getMessage());
                    }
                }
            });

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to display images on the main screen UI from a background thread

OK, there is nothing in there, but I can't check what happens in methods you call like

signInButtonClicked(phoneNumber, pinNumber);  

 

If you really have got two camView screens, then you should be able to sort out how quickly by just putting a break point in all the camView screen classes constructors. 

New Developer
Posts: 86
Registered: ‎01-20-2012
My Device: Bold Touch
My Carrier: Vodafone

Re: How to display images on the main screen UI from a background thread

yeah true i get it. i have got only one camVIew screen and in the signInButton method  calls the thread that displays images if the sign in is successful. and i pass the reference to the camView screen in to the thread.