Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

"java.lang.IllegalArgumentException: This gauge cannot be added to an Alert" unavoidable due to incorrect prefWidth/prefHeight check #105

@GoogleCodeExporter

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. Create a MidLet that adds a Gauge to an Alert and shows it (see below)
2. Test it in Oracle's emulator or real device to make sure it works
3. Test it in MicroEmulator

What is the expected output? What do you see instead?

It should work. Instead it creates this exception:

java.lang.IllegalArgumentException: This gauge cannot be added to an Alert
    at javax.microedition.lcdui.Alert.setIndicator(Alert.java:184)
    at microemu.GaugeAlert.startApp(GaugeAlert.java:17)
    at javax.microedition.midlet.MIDlet$MIDletAccessor.startApp(MIDlet.java:49)
    at org.microemu.app.Common.startMidlet(Common.java:428)

When attaching to it with a debugger, it shows that prefHeight and prefWidth 
are defined twice, once private in Item and once (shadowed) package private in 
Gauge. The variables of Gauge are both 0, and the code checks them for being -1 
(see 
http://code.google.com/p/microemu/source/browse/branches/microemulator_2_0_x/mic
roemu-midp/src/main/java/javax/microedition/lcdui/Alert.java#176). Setting them 
-1 in the debugger makes the alert visible. I could not find any code that 
tries to set these shadowed variables, so I assume it was a mistake to have 
these variables there at all.

What version of the product are you using? On what operating system?

2.0.4 on Windows XP

Please provide any additional information below.

package microemu;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class GaugeAlert extends MIDlet {

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
    }

    protected void pauseApp() {
    }

    protected void startApp() throws MIDletStateChangeException {
        Alert a = new Alert("Hello Gauge");
        a.setTimeout(Alert.FOREVER);
        a.setIndicator(new Gauge(null, false, 5, 2));
        Display.getDisplay(this).setCurrent(a);
    }
}


Original issue reported on code.google.com by schie...@gmail.com on 21 Dec 2011 at 8:03

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions