繁体   English   中英

简单的应用程序无法在Eclipse中编译(带有插件)吗?

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

我的代码实际上与BlackBerry教程中给出的代码相同,但是在Eclipse中存在语法错误。 我确定有一些小东西,但我只是没看到,但我的同事也找不到。 任何想法将不胜感激。 谢谢!

码:

pushScreen(new ABCScreen());

错误:

无法从类型UiApplication静态引用非静态方法pushScreen(Screen)

这是完整的来源:

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;
    }
}

pushScreen方法只能在UiApplication的实例中调用。 您正在尝试从静态main方法调用它。 那行不通。 改为这样做...

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

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

公共无效的class1(){pushScreen(this); }

公共静态无效main(String [] args){(new NewScreen())。class1(); }

尝试为ABCScreen类创建一个对象,然后使用它,或者您也可以尝试以下操作:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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