2011-11-03 5 views
1

나는 Android에서 왔고 지금은 Blackberry를 배우고 있습니다.Blackberry - 다른 클래스 인스턴스 컨텍스트에 액세스하기

다른 클래스에 액세스하려면 java에서 컨텍스트가 "this"와 비슷해야합니다. 어떻게 블랙 베리에서 그것을 할 수 있습니까?

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

이 변경 process1 생성자에

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

답변

3

다른 파일 클래스 : 문제는 그 코드의 다른 클래스의 예를 Screen 클래스의 필드/관리자를 추가하고 싶습니다 블랙 베리에 생성자를 호출 할 때`this`을

public process1(MyScreen screen) 
    {   
    screen.add(new Labelfield("test")); 
    } 
+0

를 사용 : 고 객 로고 목적을'process1 X = 새로운 process1 (이)' –

+0

덕분에, 왜 내가 전에이를 생각하지 않았다. :디 – Pasca

관련 문제