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
Regular Contributor
roses_r
Posts: 83
Registered: 01-20-2012
My Carrier: Vodafone

illegal Argument Exception while trying to replace a bitmapfiled

HI

 

Im trying to replace a bitmaptField from a background thread and it throws a

 

IllegalArgument Exception Manager.replace: Oldfield is not a child.

 

Is there anyway i can get this working? because what im trying is to pass images to the bitmapfield in my mainscreen. any suggestions?

 

Thanks

Please use plain text.
Developer
RexDoug
Posts: 4,649
Registered: 07-21-2008

Re: illegal Argument Exception while trying to replace a bitmapfiled

[ Edited ]

A background thread cannot operate on the GUI - only the event thread can do this.

 

You can wrap the GUI operation in a Runnable, and pass this runnable to UiApplication.invokeLater().

 

This places the GUI work in the event queue, where it will be handled by the event thread.

 

 

Please use plain text.
Regular Contributor
roses_r
Posts: 83
Registered: 01-20-2012
My Carrier: Vodafone

Re: illegal Argument Exception while trying to replace a bitmapfiled

Yeah RexDoug...Ive wrapped it in a runnable object and done hte invoke later. What i noticed was i could add a new bitmapField from the background but I cant replace the existing one.

 

Please have a look at this

 

UiApplication.getUiApplication().invokeLater(new Runnable() {
			
			public void run() 
			{
				synchronized (camView) 
				{						
					try
					{
						camView.jpegBytes = jp;
						System.out.println(bit);
						test t = new test();
						
						BitmapField bmpField = new BitmapField(bit);
						
						
						System.out.println("Replacing BitmapField.");
						t.replace(camView.bmpStream,bmpField );
						t.invalidate();
						System.out.println("Successfully replaced.");
						
						
					}
					catch(IllegalArgumentException e)
					{
						System.out.println("Exception while displaying streaming images: " + e.getMessage());
					}
				}													
			}
		});

 

Please use plain text.
Super Contributor
shahumang8
Posts: 306
Registered: 08-09-2010

Re: illegal Argument Exception while trying to replace a bitmapfiled

[ Edited ]

Hi,  roses_r

 

     You put your code like this.

 

_workThread = new Thread(new Runnable() {
				public void run() {

					try {
						
						synchronized (Application.getEventLock()) {
	                                           camView.jpegBytes = jp;
						  System.out.println(bit);
						   test t = new test();
						
						   BitmapField bmpField = new BitmapField(bit);
						
						
						   System.out.println("Replacing BitmapField.");
						   t.replace(camView.bmpStream,bmpField );
						   t.invalidate();
						   System.out.println("Successfully replaced.");
						}

					} catch (Exception e) {
					}
				}
			});
			_workThread.start();

 

I hope you error sloved.

Please use plain text.
Regular Contributor
roses_r
Posts: 83
Registered: 01-20-2012
My Carrier: Vodafone

Re: illegal Argument Exception while trying to replace a bitmapfiled

whats this processSuccess method u have used?

Please use plain text.
Super Contributor
shahumang8
Posts: 306
Registered: 08-09-2010

Re: illegal Argument Exception while trying to replace a bitmapfiled

Sorry.There are some extra field now i edit my old post so check it out,

 

Thanks.

Please use plain text.
Regular Contributor
roses_r
Posts: 83
Registered: 01-20-2012
My Carrier: Vodafone

Re: illegal Argument Exception while trying to replace a bitmapfiled

well i removed them before and tried as well..didnt work for me

 

still throws an excception saying

Manager.replace: Old field is not a child

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: illegal Argument Exception while trying to replace a bitmapfiled

Have a look at my response in the other Thread in which you posted a similar question:

http://supportforums.blackberry.com/t5/Java-Development/Manager-replace-returns-IllegalArgumentExcep...

Please use plain text.