×
Namespaces

Variants
Actions
(Difference between revisions)

Utilizing Alert in viewing output data

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - metadata, code example, featured article or Qwidget UI fixes)
hamishwillee (Talk | contribs)
Line 22: Line 22:
 
|author= [[User:Jarmlaht]]
 
|author= [[User:Jarmlaht]]
 
}}
 
}}
[[Category:Java ME]][[Category:How To]][[Category:Code Snippet]][[Category:Debugging]]
+
[[Category:Java ME]][[Category:How To]][[Category:Code Snippet]][[Category:Debugging on Java ME]]
  
 
It is a common way to use <tt>System.out.println("whatever output information");</tt> 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:
 
It is a common way to use <tt>System.out.println("whatever output information");</tt> 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:

Revision as of 07:50, 25 July 2013

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

53 page views in the last 30 days.
×