Wednesday, January 23, 2008

J2ME

We've released new LivTv version last week. Encountering J2ME technology for the first time was fun ( I mean it ). But device dependency was the real pain in the ass.Here are some learned-in-hard-way facts for the newbies in the brave new world of J2ME.

  • Never ever believe your emulator . Build incrementally and run the program in the widest number of devices possible.

  • If any program runs smoothly in other devices but seems to hang in Nokia N70, check if there is any UnsupportedOperationException(default action in newly created functions in NetBeans) anywhere . NokiaN70 stalls at the very sight of UnsupportedOperationException even if it has not been thrown during runtime.


  • Do not calculate the height or width of the canvas in the constructor of any class derived from abstract Canvas class. Some phones returns wrong result when Canvas.getHeight() or Canvas.getWidth() is called in the constructor .

  • Never ever draw anything using absolute pixel distance . It is destined to make a mess for phones having different resolutions. Instead make it as general as possible . For example if you are drawing a string surrounded by a rectangle , then use stringWidth() or getHeight() methods declared in Font class to calculate the height and width of surrounding rectangle. Remember the first law, Do not believe the emulator.

  • Trying to access camera in a Samsung device by using J2ME API may turn out as a waste of time.

  • Some Samsung devices place icons and other informations at the top of the canvas. So dont just start to draw from (0,0), make it dynamical too.

  • J2ME threads are somehow different than Java threads. In J2ME , one thread can not stop, pause or resume another thread, keeping that in mind during design may save from lot of head scratching later.

  • Adding multiple commands in an alert may cause weird behavior in NokiaN90.

  • If URL contains "|" ( pipe symbol ) , NokiaN95 fails to open that Http Connection . One way around it is using Base64 encoder and decoder .

Hope, this helps.