Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Utilizing Alert in viewing output data

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: jarmlaht (15 Jun 2007)
Last edited: hamishwillee (25 Jul 2013)


It is a common way to use System.out.println("whatever output information"); lines in Java code for getting output from a MIDlet, while developing MIDlets. This works well in SDKs, while it is more difficult to get information, when MIDlet is run in a real device. Simple way of getting output is using Alert Screen for getting output. This is especially useful for getting error messages from Exceptions. The following code shows, how to use Alerts for this:

    void alertError(String message) {
Alert alert = new Alert("Error", message, null, AlertType.ERROR);
Display display = Display.getDisplay(this);
Displayable current = display.getCurrent();
if (! (current instanceof Alert)) {
// This next call can't be done when current is an Alert
display.setCurrent(alert, current);
}
}

Then you can call the method for example like this:

try {
player = Manager.createPlayer(song);
player.addPlayerListener(this);
player.realize();
vc = (VolumeControl) player.getControl("VolumeControl");
vc.setLevel(50);
player.setLoopCount( -1);
player.prefetch();
player.start();
}
catch (IOException ioe) {
alertError("IOException: " + ioe.getMessage());
}
catch (MediaException me) {
alertError("MediaException: " + me.getMessage());
}

Other links

This page was last modified on 25 July 2013, at 05:00.
87 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×