02-28-2009 06:46 PM
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
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());
}
}
02-28-2009 11:45 PM
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
03-01-2009 04:27 AM
03-02-2009 10:13 AM
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
03-02-2009 02:10 PM
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.
03-02-2009 02:14 PM - edited 03-02-2009 02:15 PM
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;
}
}
03-05-2009 03:33 PM
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.