简体   繁体   English

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

[英]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. 我的代码实际上与BlackBerry教程中给出的代码相同,但是在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 无法从类型UiApplication静态引用非静态方法pushScreen(Screen)

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. pushScreen方法只能在UiApplication的实例中调用。 You are trying to call it from a static main method. 您正在尝试从静态main方法调用它。 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); 公共无效的class1(){pushScreen(this); } }

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

try making an object for the ABCScreen class and then use it or u may try this also: 尝试为ABCScreen类创建一个对象,然后使用它,或者您也可以尝试以下操作:

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

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

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