如何使用Java在BlackBerry应用程序中设置背景图像?

如何使用Java在BlackBerry应用程序中设置背景图像?,blackberry,Blackberry,如何在java blackberry模拟器中设置背景图像 backgroundBitmap = Bitmap.getBitmapResource("background.png"); MainScreen mainScreen = new MainScreen(); HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager( HorizontalFieldManager.USE

如何在java blackberry模拟器中设置背景图像

backgroundBitmap = Bitmap.getBitmapResource("background.png");
MainScreen mainScreen = new MainScreen();

HorizontalFieldManager horizontalFieldManager = 
    new HorizontalFieldManager(
        HorizontalFieldManager.USE_ALL_WIDTH | 
        HorizontalFieldManager.USE_ALL_HEIGHT){

        //Override the paint method to draw the background image.
        public void paint(Graphics graphics) {
            //Draw the background image and then call paint.
            graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0);
            super.paint(graphics);
        }            

    };
试试这篇博文:

或此支持论坛帖子:

如果你搜索论坛,你可以找到具有相同信息的各种帖子。空指针异常表示代码无法获取png文件。你将文件“background.png”放在哪里了?我将png图像复制到项目的res文件夹中,请检查文件名的拼写,可能就是这个问题。如果您遇到任何特定的问题或异常,请发布一些代码,否则没有人能够调试您的问题。请确保您在代码中输入了正确的图像文件名。在您的情况下,空指针异常很可能是因为文件名错误。或文件不存在。。如果您刚刚添加了该文件并使用eclipse,请检查该图像在树视图中是否可用。。如果没有,则在res文件夹中,并且您已复制到该文件夹中。。按F5,然后再次尝试运行它。您是否尝试过调试以检查发生空指针异常的确切位置?
     Bitmap bitmapOrig = Bitmap.getBitmapResource("ICON.png");            
      // Create a Bitmap of arbitrary size
      int scaledX = 360;
      int scaledY = 415;
      Bitmap bitmapScaled = new Bitmap(scaledX, scaledY);
      bitmapOrig.scaleInto(bitmapScaled , Bitmap.FILTER_LANCZOS);                       
      bitmapOrig.scaleInto(bitmapScaled , Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);                       
      BitmapField bitmapFieldScaled2 = new BitmapField(bitmapScaled , Field.FOCUSABLE);
     homeScreen.add(bitmapFieldScaled2);
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(
                                HorizontalFieldManager.USE_ALL_WIDTH | 
                                HorizontalFieldManager.USE_ALL_HEIGHT){

    //Override the paint method to draw the background image.
    public void paint(Graphics graphics) {
        //Draw the background image and then call paint.
        graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0);
        super.paint(graphics);
    }    
   protected void sublayout(int maxWidth, int maxHeight){ 
            super.sublayout(240,240);
            setExtent(240,240);
        }        

};