×
Namespaces

Variants
Actions
(Difference between revisions)

Utilizing Alert in viewing output data

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix categories)
 
Line 1: Line 1:
 +
[[Category:Debugging on Java ME]][[Category:How To]][[Category:Code Snippet]]
 
{{ArticleMetaData <!-- v1.1 -->
 
{{ArticleMetaData <!-- v1.1 -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
Line 4: Line 5:
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
Line 22: Line 19:
 
|author= [[User:Jarmlaht]]
 
|author= [[User:Jarmlaht]]
 
}}
 
}}
[[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:

Latest revision as of 08:00, 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());
}

[edit] Other links

This page was last modified on 25 July 2013, at 08:00.
48 page views in the last 30 days.
×