2012-01-16 69 views
0

我已经在我的UiApplication类中尝试了这段代码,但是我收到了非法状态的错误。黑莓:将应用程序限制为肖像模式

Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT); 

我不希望我的应用程序改变其方向。我希望它保持肖像模式。

编辑:

如何使用它:

public class HelloWorld extends UiApplication { 


    public static void main(String[] args){ 

     Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT); 


     HelloWorld theapp = new HelloWorld(); 
     theapp.enterEventDispatcher(); 

    } 


    public HelloWorld(){ 

     pushScreen(new FeaturedScreen()); 

    } 


} 
+0

你调用UiApplication.pushScreen之前使用这个() – Swati 2012-01-16 04:41:06

回答

3
DemoClass() 
{ 
    int direction = Display.DIRECTION_PORTRAIT; 
    Ui.getUiEngineInstance().setAcceptableDirections(direction); 
    pushScreen(new AppScreen(this));   
} 
public static void main(String[] args) { 
    DemoClass app1 = new DemoClass();      
    app1.enterEventDispatcher(); 
} 
1
public class HelloWorld extends UiApplication { 
    public static void main(String[] args){ 
     UiEngineInstance ui = Ui.getUiEngineInstance();//I have added this new line in your code 
     ui.setAcceptableDirections(Display.DIRECTION_NORTH); 
     HelloWorld theapp = new HelloWorld(); 
     theapp.enterEventDispatcher(); 
    } 

    public HelloWorld(){ 
    pushScreen(new FeaturedScreen()); 
    } 
}