2

I have just started to learn the basics of Blackberry....

So, I am facing one issue in Bitmap UI API of Blackberry..

I have a class called UiFunApplication which have main method :

public class UiFunApplication extends UiApplication {
    public UiFunApplication() {
        UiFunMainScreen mainScreen = new UiFunMainScreen();
        pushScreen(mainScreen);
    }

    public static void main(String[] args) {
        UiFunApplication app = new UiFunApplication();
        app.enterEventDispatcher();
    }
}

Now my UiMainScreen Class have following code :

public class UiFunMainScreen extends MainScreen {

    BitmapField bitmapField;

    public UiFunMainScreen() {
        Bitmap logoBitmap = Bitmap.getBitmapResource("res/image.png");
        bitmapField = new BitmapField(logoBitmap,Field.FIELD_HCENTER);
        add(bitmapField);

        LabelField labelField = new LabelField("Hello World");
        add(labelField);

    }
}

I have also included image.png in the res folder which is in the same directory structure as src.

Still in the simulator I am just getting the label called "Hello World", but not the image at the top.

Thanks in advance....

4

1 に答える 1

6

Eclipseの最新のBlackBerryプラグインは、J2MEのresフォルダー規則を使用しています。resフォルダー内のすべてがjarファイルの最上位になります。

だからラインを変更する

Bitmap logoBitmap = Bitmap.getBitmapResource("res/image.png");

Bitmap logoBitmap = Bitmap.getBitmapResource("image.png");

問題を修正する必要があります。

これが問題であることを確認するには、プロジェクトディレクトリの成果物フォルダでEclipseによって生成されたjarを探します。それを開き(拡張子を.zipに変更するだけです)、画像がjarのトップレベルにあることを確認します。

resをそこに配置したい場合は、resフォルダーの下に別のresフォルダーを追加し、そこにすべての画像を配置します。

于 2010-05-11T13:58:12.280 に答える