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());
}
No related wiki articles found