Switch to a Visual Design from another Visual Design

社会主义新天地 提交于 2019-12-11 03:13:22

问题


I'm working in java me. I created two visual designs, First.java and Second.java both of which contains form displayables.

I added an Ok command to a form in First.Java and the user is expected to switch to SecondForm in Second.java but I get this error non-static method getSecondForm() cannot be referenced from a static context.

How can I fix this?

Both files are in the same package. Here's the source code

 public void commandAction (Command command, Displayable displayable) {

    if (displayable == firstForm) {

        if (command == exitCommand) {
            exitMIDlet();

        } else if (command == okCommand) {

            switchDisplayable(null, Second.getSecondForm());
        }
    }
 }

回答1:


You need to change declaration of the method getSecondForm in Second.java to make it static.

If it currently looks like

Displayable getSecondForm() //... whatever code is there

then after change it should look like

static Displayable getSecondForm() //... whatever code is there

Note above change will fix the non-static method getSecondForm... error you mentioned but there is a chance that it will cause new compilation errors in file Second.java. You will need to fix these new errors, most likely by adding couple static keywords here and there, similar to how it is shown above.


Note this is java language basic stuff; if you get stuck fixing this, consider taking a break to study some tutorial for beginners.



来源:https://stackoverflow.com/questions/14068709/switch-to-a-visual-design-from-another-visual-design

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!