FileDocCategorySizeDatePackage
DisplayError.javaAPI DocphoneME MR2 API (J2ME)5535Wed May 02 18:00:06 BST 2007com.sun.midp.appmanager

DisplayError

public class DisplayError extends Object
Displays error messages using the Display instance object passed into the Constructor.

Fields Summary
Display
display
The display instance to be used to display error alerts
Constructors Summary
DisplayError(Display display)
Creates a DisplayError instance given a display object.

param
display the Display instance where Alerts will the errors will be shown

        this.display = display;
    
Methods Summary
voidshowCorruptedSuiteAlert(java.lang.String msg)
Display an alert screen when midlet suite is corrupted

param
msg Message to display on alert

        Alert a = new Alert(Resource.getString
                            (ResourceConstants.AMS_CANT_ACCESS),
                            msg, null, AlertType.ERROR);
        a.setTimeout(2000);
        display.setCurrent(a, display.getCurrent());
    
voidshowErrorAlert(java.lang.String appName, java.lang.Throwable t, java.lang.String alertTitle, java.lang.String alertMessage)
Display the Alert with the error message.

param
appName - name of the application in which the error happen
param
t - throwable that was thrown while performing one of the operations on the application
param
alertTitle - if non-null it will be the Alert title, otherwise a default value will be used (Resource.getString(ResourceConstants.AMS_CANNOT_START))
param
alertMessage - if non-null it will be the Alert message, otherwise a default message will be generated using (Resource.getString(ResourceConstants.ERROR))

        showErrorAlert(appName, t, alertTitle, alertMessage, null);    
    
voidshowErrorAlert(java.lang.String appName, java.lang.Throwable t, java.lang.String alertTitle, java.lang.String alertMessage, Displayable nextDisplayable)
Display the Alert with the error message.

param
appName - name of the application in which the error happen
param
t - throwable that was thrown while performing one of the operations on the application
param
alertTitle - if non-null it will be the Alert title, otherwise a default value will be used (Resource.getString(ResourceConstants.AMS_CANNOT_START))
param
alertMessage - if non-null it will be the Alert message, otherwise a default message will be generated using (Resource.getString(ResourceConstants.ERROR))
param
nextDisplayable the Displayable to be shown after the error alert is dismissed; can be null


        if (alertMessage == null) {

            if (t instanceof MIDletSuiteLockedException) {
                String[] values = new String[1];
                values[0] = appName;
                alertMessage = Resource.getString(
                                   ResourceConstants.AMS_MGR_UPDATE_IS_RUNNING,
                                   values);
            } else if (t instanceof MIDletSuiteCorruptedException) {
                String[] values = new String[1];
                values[0] = appName;
                alertMessage = Resource.getString(
                            ResourceConstants.AMS_MIDLETSUITE_ID_CORRUPT_MSG,
                            values);
            } else {

                t.printStackTrace();

                StringBuffer sb = new StringBuffer();
                
                sb.append(appName);
                sb.append("\n");
                sb.append(Resource.getString(ResourceConstants.ERROR));
                sb.append(": ");
                sb.append(t.toString());
                alertMessage = sb.toString();
            }
        
        }

        if (alertTitle == null) {
            alertTitle = 
                Resource.getString(ResourceConstants.AMS_CANNOT_START);
        }
        Alert a = new Alert(alertTitle, alertMessage, null, AlertType.ERROR);
        a.setTimeout(Alert.FOREVER);

        if (nextDisplayable == null) {
            display.setCurrent(a);
        } else {
            display.setCurrent(a, nextDisplayable);
        }