Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
ecompean
Posts: 5
Registered: ‎02-28-2009
My Device: Not Specified

Bitmap Problem

Hi, I am havig problem trying to load an image in my aplication,

 

my proyect path is:

C:\Archivos de programa\Research In Motion\BlackBerry JDE 4.7.0\bin\MMedios\multimedios.java

                                                                                                             \img\rainbow.png

 

the .png image doesn't have anything wrong, it was taken from a example package, and was used in the example code, and worked fine (the example aplication was build correctly, ant the simulator loaded the .png image.

 

in the debuger says tha the img variable is null.

 

 

thanks in advance for your help.

 

 

****************** CODE ****************


import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

public class multimedios extends UiApplication {
    public static void main(String[] args) {
        multimedios theApp = new multimedios();
        theApp.enterEventDispatcher();
    }
    public multimedios() {
        pushScreen(new FieldExamplesScreen());
    }
}

final class FieldExamplesScreen extends MainScreen {
   
    public FieldExamplesScreen() {
        super();
       
        // Setting page title
        LabelField lf = new LabelField("Multimedios", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(lf);
       
        // LabelField variations
        add(new LabelField("LabelField"));
        add(new LabelField("LabelField 2", 0, -1, Field.FIELD_RIGHT));
        LabelField lbl = new LabelField("LabelField 3", 0, -1, Field.FIELD_HCENTER);
        Font fnt = this.getFont().derive(Font.BOLD | Font.ITALIC);
        lbl.setFont(fnt);
        add(lbl);
       
        add(new SeparatorField());
       
        // RichTextField variations
        add(new RichTextField("RichTextField"));
        String str[] = new String[] {"RichTextField:", "Value"};
        int off[] = new int[] {0, str[0].length(), str[0].length() + str[1].length()};
        byte attr[] = new byte[] {0, 1};
        FontFamily fontfam[] = FontFamily.getFontFamilies();
        Font fon[] = new Font[2];
        fon[0] = fontfam[0].getFont(FontFamily.SCALABLE_FONT, 16);
        fon[1] = fontfam[1].getFont(FontFamily.SCALABLE_FONT, 18);
        add(new RichTextField(str[0] + str[1], off, attr, fon, RichTextField.TEXT_ALIGN_HCENTER));
       
        add(new SeparatorField());
       
        // EditField
        EditField edit = new EditField("Username: ", "");
        add(edit);
       
        // PasswordEditField
        PasswordEditField pass = new PasswordEditField("Password: ", "");
        add(pass);
       
        add(new SeparatorField());
       
        // Listfield (must have a callback)
        ListField list = new ListField();
        list.setEmptyString("Nothing to see here", DrawStyle.LEFT);
        list.setSize(3);
        list.setCallback(new TestListCallback());
        add(list);
       
        add(new SeparatorField());
       
        // BitmapField
        Bitmap img = Bitmap.getBitmapResource("com/examples/img/rainbow.png");
        BitmapField bf = new BitmapField(img, BitmapField.FOCUSABLE);
        add(bf);
       
        add(new SeparatorField());
       
        // ButtonField
        ButtonField btn = new ButtonField("myButton");
        ButtonField btn2 = new ButtonField("Second Button");
        btn.setChangeListener(new ButtonListener());
        btn2.setChangeListener(new ButtonListener());
        add(btn);
        add(btn2);
       
        add(new SeparatorField());
       
        // RadioButtonField (must be part of group)
        RadioButtonGroup rgrp = new RadioButtonGroup();
        RadioButtonField radio = new RadioButtonField("Radio Button", rgrp, true);
        RadioButtonField radio2 = new RadioButtonField("Radio 2", rgrp, false);
        add(radio);
        add(radio2);
       
        add(new SeparatorField());
       
        // CheckboxField
        CheckboxField chk = new CheckboxField("Checkbox 1", true);
        CheckboxField chk2 = new CheckboxField("Checkbox 2", false);
        add(chk);
        add(chk2);
       
        add(new SeparatorField());
       
        // ObjectChoiceField
        String choicestrs[] = {"Opt 1", "Opt 2", "Opt 3"};
        ObjectChoiceField choice = new ObjectChoiceField("Object Choice Field: ", choicestrs, 0);
        add(choice);
       
        // NumericChoiceField
        NumericChoiceField numeric = new NumericChoiceField("Numeric Choice Field: ", 1, 10, 1, 4);
        add(numeric);
       
        // GaugeField
        GaugeField gauge = new GaugeField("Gauge Field: ", 1, 100, 50, Field.EDITABLE | Field.FOCUSABLE);
        add(gauge);
       
        // DateField
        DateField dte = new DateField("Date Field: ", Long.MIN_VALUE, DateField.DATE);
        add(dte);

    }
   
    public boolean onClose() {
        Dialog.alert("Goodbye!");
        System.exit(0);
        return true;
    }
}

final class TestListCallback implements ListFieldCallback {
    public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
        g.drawText("Testing:", 0, y, 0, w);
        g.drawText(String.valueOf(index * 111), 0, y, DrawStyle.RIGHT, w);
    }
    public Object get(ListField listField, int index) {
        return null;
    }
    public int getPreferredWidth(ListField listField) {
        return Graphics.getScreenWidth();
    }
    public int indexOfList(ListField listField, String prefix, int start) {
        return listField.indexOfList(prefix, start);
    }
}

final class ButtonListener implements FieldChangeListener {
    public void fieldChanged(Field field, int context) {
        ButtonField btn = (ButtonField) field;
        Status.show("Button pressed: " + btn.getLabel());
    }
}

 

New Developer
ecompean
Posts: 5
Registered: ‎02-28-2009
My Device: Not Specified

Re: Bitmap Problem

I know it should be very easy to use this lines:

 

Bitmap img = Bitmap.getBitmapResource("/rainbow.png");      
        BitmapField bf = new BitmapField(img, BitmapField.FOCUSABLE);
        add(bf);

 

but is really not working. I have the rainbow.png file in the same path of the rest of my proyect.

 

hope someone can help me.

 

Ernesto

Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Bitmap Problem

I had a similar issue with the 4.7 JDE and removing the slash on the image name solved it for me.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Bitmap Problem

Hi,

I guessyou should try this , hopefully this will solve your problem.

 

just remove slash from your image name and add this image into your project by right clicking on your project and selecting this image.

 

just let me know if you have any query.

 

Regards,

Rajat Gupta.

 


If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish

 

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
New Developer
ecompean
Posts: 5
Registered: ‎02-28-2009
My Device: Not Specified

Re: Bitmap Problem

Hi,

 

Thank yor very much. UI didn't realize that i had to add the file to the proyect, It is working ok now.

 

Best Regards.

 

 

New Developer
blueskyjunkie
Posts: 4
Registered: ‎03-01-2009
My Device: Not Specified

Re: Bitmap Problem

[ Edited ]

I have a similar problem. This is the first BB app that I've ever written so it's very simple, but I can't get my background image to appear.

 

 

package com;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;


//**************************************************************************************
//ScreenClick.java Author: M@
//
//**************************************************************************************
public class ScreenClick extends MainScreen{

Bitmap backgroundBitmap = Bitmap.getBitmapResource("twss.png");

public static void main(String[] args) {

new ScreenClick().enterEventDispatcher();

}

public ScreenClick()
{

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

ScreenClick screen = new ScreenClick();

pushScreen(screen);

TouchEvent.getEvent();

}

public void paint(Graphics graphics)
{

graphics.drawBitmap(0, 0, graphics.getScreenWidth(), graphics.getScreenHeight(),
backgroundBitmap, 0, 0);
super.paint(graphics);

}

protected boolean touchEvent(TouchEvent message)
{

TouchEvent.getEvent();

switch(message.getEvent()) {
case TouchEvent.CLICK:
return true;

}

return false;

}

}

 

 

 

Message Edited by blueskyjunkie on 03-02-2009 02:15 PM
BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Bitmap Problem

Has the icon been added to your project?  Are you using the BlackBerry JDE or BlackBerry JDE Plug-in for Eclipse?  There is an issue with the beta release of the plug-in where it places image files a src folder on the application.

 

You can update to the gold release of the plug-in to resolve this issue.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker