Skip to main content

N95 8 Gb LWUIT throws IllegalArgumentException when calling Form.show()

4 replies [Last post]
kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Hello all,

I'm using a MediaComponent to display the camera in order to take an snapshot. I have a class with methods for accessing any of the screens in the MIDlet, the splash, the capture, ...

MIDlet.startApp() does the following:

<br />
Display.init(this);<br />
UIManager.getInstance().setLookAndFeel(new CustomLookAndFeel());<br />
ScreenManager.getInstance(this).showSplash();<br />

And here's the source code for showing the screens.

<br />
public void showSplash() {<br />
	final Form splash = new Form();<br />
	Image image = null;<br />
	splash.setScrollable(false);<br />
	splash.setLayout(new BorderLayout());</p>
<p>	final Label img = new Label() {<br />
		long t = System.currentTimeMillis();<br />
		public boolean animate() {<br />
			if (System.currentTimeMillis() - t >= 2000) {<br />
				splash.deregisterAnimated(this);<br />
				showCapture();<br />
				return false;<br />
			}<br />
			return true;<br />
		}<br />
	};</p>
<p>	try {<br />
		Resources res = Resources.open("/IBSTheme.res");<br />
		UIManager.getInstance().setThemeProps(res.getTheme("mainTheme"));</p>
<p>		image = Resources.open("/images.res").getImage("logo");</p>
<p>		if (image.getWidth() > Display.getInstance().getDisplayWidth()) {<br />
			float ratio = (float)((float)image.getWidth() / (float)image.getHeight());<br />
			image = image.scaledSmallerRatio(Display.getInstance().getDisplayWidth(),<br />
(int)((float)image.getHeight()/ratio));<br />
		}</p>
<p>		img.setIcon(image);<br />
		img.setAlignment(Label.CENTER);<br />
		splash.addComponent(BorderLayout.CENTER, img);<br />
		splash.registerAnimated(img);<br />
	} catch (Exception e) {<br />
		e.printStackTrace();<br />
	}<br />
	splash.refreshTheme();<br />
	splash.show();<br />
}</p>
<p>public void showCapture() {<br />
	data=null;<br />
	//imgPreview = null;<br />
	try {<br />
		_showCapture();<br />
	} catch (MediaException me) {<br />
		me.printStackTrace();<br />
		showError(Constants.ERROR_TITLE, Constants.ERROR_MMAPI_PLAYER);<br />
	} catch (IOException ioe) {<br />
		ioe.printStackTrace();<br />
		showError(Constants.ERROR_TITLE, Constants.ERROR_MMAPI_PLAYER);<br />
	}<br />
}</p>
<p>private void _showCapture() throws MediaException, IOException {<br />
	final Player mPlayer = Manager.createPlayer(Constants.MMAPI_CAPTURE);<br />
	mPlayer.realize();<br />
	final MediaComponent video=new MediaComponent(mPlayer);</p>
<p>	Form capture = new Form() {<br />
		public void keyPressed(int keyCode) {<br />
			if (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE) {<br />
				VideoControl vControl = (VideoControl) mPlayer.getControl(Constants.MMAPI_VIDEOCONTROL);<br />
				try {<br />
					data = vControl.getSnapshot("encoding=jpeg&width=640&height=480");<br />
					mPlayer.stop();<br />
					vControl.setVisible(false);<br />
					showPreview(data);<br />
				} catch (MediaException me) {<br />
					me.printStackTrace();<br />
					showError(Constants.ERROR_TITLE, Constants.ERROR_MMAPI_CAPTURE);<br />
				}<br />
			}<br />
		}<br />
	};</p>
<p>	capture.setScrollable(false);<br />
	capture.setLayout(new BorderLayout());<br />
	capture.addComponent(BorderLayout.CENTER, video);</p>
<p>	video.setFocusable(false);<br />
	capture.show();<br />
	mPlayer.start();<br />
}<br />

First, the splash screen is shown. After 2000 ms, showCapture() is called, and in _showCapture(), where I do capture.show() an IllegalArgumentException is thrown. This works nicely on the emulator.

I guess the problem is with MediaComponent because there aren't any other Components in the Form. Probably I forgot to initialize something? Could be the Player.start() before showing the Form?

Any idea is welcomed, Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Hi again,

I've been checking (as I could, cause now I only have a N90 to test on). I've tried the same exact MIDlet as in N95 and it worked well, no IllegalArgumentException thrown.

I examined when this Exception is thrown in MMAPI when initializing, and I saw 2 possible locations:
- initDisplayMode(int, Object) or
- setDisplaySize(int, int) [if negative size]

MediaComponent internally make calls to Display.getVideocontrol(), this one to Implementation.getVideoControl() and this one to mmapi initDisplayMode, and I think this is what's throwing the Exception. Why on N95 yes and on N90 no? who knows...

Anyone can try the above code in a N95 and let us know if the Exception is thrown too? btw the fw is V10.0.021

Thanks

kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Hi all there,

after having a new N95, the same exception was being thrown. To solve it, just call Player.start() before calling Form.show().

If you try to setMargin() (and probably many other methods related to how video is displayed) before Player.start(), this will thrown another IllegalArgumentException.

Also, MediaComponent.start() and stop() doesn't seem to have any effect. The methods must be called directly to Player instead of MediaComponent. Is this the expected behaviour?

Regards

Edit to add comment about setMargin()

Message was edited by: kawaiimomo

Shai Almog

Hi kawaiimomo,
I'm guessing here without a specific line. This seems like an
exception related to the media capture on N95 since MMAPI throws
IllegalArgumentException's all over the place.
You can just wrap your code with try/catch and update a variable to
indicate the line number that fails.

Check this URL for supported video encoding detection in Nokia, I
would guess that is the problem in your code: http://
wiki.forum.nokia.com/index.php/MMAPI

Thanks

> I'm using a MediaComponent to display the camera in order to take
> an snapshot. I have a class with methods for accessing any of the
> screens in the MIDlet, the splash, the capture, ...
>
> http://forums.java.net/jive/thread.jspa?messageID=290060
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Hi Shai,
as I say in the previous post, the exception is thrown when calling Form.show(), so it has to be the MediaComponent.

Thanks.