从另一个视觉设计切换到视觉设计 [英] Switch to a Visual Design from another Visual Design
问题描述
我正在用Java工作.我创建了两个视觉设计,First.java和Second.java,它们都包含表单可显示内容.
I'm working in java me. I created two visual designs, First.java and Second.java both of which contains form displayables.
我在First.Java中的表单中添加了一个Ok命令,希望用户在Second.java中切换到SecondForm,但是出现此错误non-static method getSecondForm() cannot be referenced from a static context
.
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
.
我该如何解决?
两个文件都在同一个程序包中.这是源代码
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());
}
}
}
推荐答案
您需要在Second.java中更改方法getSecondForm
的声明以使其静态.
You need to change declaration of the method getSecondForm
in Second.java to make it static.
如果当前看起来像
Displayable getSecondForm() //... whatever code is there
然后在更改后它应该看起来像
then after change it should look like
static Displayable getSecondForm() //... whatever code is there
请注意,上述更改将解决您提到的non-static method getSecondForm...
错误,但有可能会导致文件Second.java
中出现新的编译错误.您将需要修复这些新错误,最有可能的是在此处和此处添加几个static
关键字,类似于上面的显示方式.
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.
请注意,这是java 语言基本的东西;如果您无法解决此问题,请考虑休息一下,为初学者学习一些教程.
Note this is java language basic stuff; if you get stuck fixing this, consider taking a break to study some tutorial for beginners.
这篇关于从另一个视觉设计切换到视觉设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!