简体   繁体   中英

Simple App Won't Compile in Eclipse (with plugin)?

my code, being practically identical to the code given in BlackBerry's tutorial, has a syntax error in Eclipse. i'm sure there is some small but i'm just not seeing, but my coworker could not find it as well. any ideas would be greatly appreciated. thanks!

Code:

pushScreen(new ABCScreen());

Error:

Cannot make a static reference to the non-static method pushScreen(Screen) from the type UiApplication

here is the complete source:

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;


public class AwesomeBBCalculator extends UiApplication {

    public AwesomeBBCalculator() {
        AwesomeBBCalculator app = new AwesomeBBCalculator();
        app.enterEventDispatcher();
    }

    public static void main(String[] args) {
        pushScreen(new ABCScreen()); // ERROR LINE
    }

}

final class ABCScreen extends MainScreen {
    public ABCScreen() {
        super();

        // add title
        LabelField title = new LabelField("Awesome BlackBerry Calculator",
                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(title);
    }

    public boolean onClose() {
        Dialog.alert("Thanks for using the Awesome BlackBerry Calculator!\nGoodbye.");
        System.exit(0);
        return true;
    }
}

The pushScreen method can only be called within an instance of UiApplication. You are trying to call it from a static main method. That does not work. Do this instead...

public void foo()
{
    pushScreen(this);
}

public static void main(String[] args)
{
    (new ABCScreen()).foo();
}

public void class1() { pushScreen(this); }

public static void main(String[] args) { (new NewScreen()).class1(); }

try making an object for the ABCScreen class and then use it or u may try this also:

UiApplication.getUiApplication().pushScreen(new ABCScreen());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM