我来自Android,现在我正在学习Blackberry。
在Android中访问其他类我们可以在java中传递类似“this”的上下文。怎么在黑莓手机上做到这一点?问题出在Blackberry我想在其他类中添加一个Screen类的字段/管理器,例如代码:
public final class MyScreen extends MainScreen
{
//Creates a new MyScreen object
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
process1 x = new process1(); // will add the labelfield
}
}
这在其他文件类
中public class process1
{
public process1()
{
//i'm trying to get the context of MyScreen so i can add the field in this class
MyScreen.add(new Labelfield("test"));
//but its giving error with the message cannot make static reference
}
}
答案 0 :(得分:3)
更改process1构造函数以获取MyScreen对象:
public process1(MyScreen screen)
{
screen.add(new Labelfield("test"));
}