views:

2154

answers:

8

When writing j2me applications for cellphones, using System.out.println() prints on the console if using an emulator. However, when the code is deployed on a cellphone, where does the console output go?

If it is impossible to see this in the untethered cellphone, is there a way to see it if the cellphone is still connected to the deploying PC [via USB] ?

Thanks

+2  A: 

I found this question with answers on j2me logging. Maybe one can try this if nothing else works. A simple way to access System.out.println() would be nice though.

Animesh
A: 

The only input I can offer is that this will differ greatly on each platform. I work mainly with BlackBerrys and System.err goes to the devices event log but I have no idea where System.out goes.

roryf
+1  A: 

The simple answer is: nowhere you can see them. It does print somewhere (since loads of phones slow down if you have loads of prints) but, on most phones, there's no way to access it.

Some devices do display the console output, for example Sony Ericssons, which show it all if tethered and running the on-device debugging program. You can find out which do it and which don't by searching the developer sites (if they exist) of the various manufacturers.

Your best bet is to write a small method that appends to a StringBuffer within your program. Then map a key press that will display the contents of the StringBuffer on screen. It is invaluable for searching for those nasty device issues.

Shane Breatnach
A: 

You should also be sure to not include println in your production code.

I have seen some phones that actually have a memory leak when doing this (e.g. Sanyo 8400 on Sprint.

Hortitude
A: 

Logging on devices is always a problem with J2ME because there's not a standard implementation for it. I can address you to GEAR. It's a J2ME graphic framework that implements also a "in-device" debug console where you can print your lines and display them on your screen.

Stefano Driussi
A: 

BlackBerry J2ME devices for example can be connected to the computer and the debugger can connect to that device. Once you run a program on the actual device, your System.out OutputStream goes to the debugger console.

kozen
+1  A: 

On Symbian phones (Nokia, Sony-Ericsson, Motorola, Samsung, Panasonic, Siemens, check for the Series60, Series80, Series90 or UIQ platforms), You can retrieve both System.out and System.err. Most importantly, you can retrieve Throwable.printStackTrace() as well.

Early versions of Symbian OS came with a native tool called Redirector. It ended up becoming available to third party MIDlet developers too. It might be hard to find these days but can be re-developed using C++ code that plugs into the Symbian implementation of the C standard library that the Java Virtual Machine uses.

Newer versions of Symbian OS come with an additional GCF protocol that allows retrieval of System.out, System.err and Throwable.printStackTrace() by simply using

javax.microedition.io.Connector.openDataInputStream("redirect://");

You may need to use "redirect://test" on some versions of Series60, during the transition from the Sun Ltd cldc-hi virtual machine to the IBM J9 virtual machine.

The connection needs to be opened before you launch the MIDlet whose output you want to log so you'll need to open it in a separate MIDlet.

QuickRecipesOnSymbianOS
+1  A: 

Thank you for your response QuickRecipesOnSymbian.

In the following article you can find a corresponding J2ME MIDlet to display the standard error/output on Symbian phones:

http://wiki.forum.nokia.com/index.php/How_to_get_System.out_output_from_a_MIDlet_and_save_it_to_a_file_in_S60_devices

The solution works fine on Samsung i8910 as well. (As I'm a newbie on this site, I could not post more than one links, so you need to find the zip with the sources and the jar at the end of the article.)