If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
praveensingh18
Posts: 13
Registered: ‎02-10-2012
My Device: Curve 9300 3G
My Carrier: CellC
Accepted Solution

Background with custom layout error

Hi 

 

I have a MainScreen that I have set to use a background image, and I have created a custom HFM layout

but when I use my custom layout on the screen I get an error 104 uncaught illegal argument exception.

 

When I remove the code for the background image, the mainscreen displays correctly with my custom layout,

how can I use my custom layout with a background image.

 

Thanks

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Background with custom layout error

We can't tell you anything more.  You need to run you application in debug mode.  So just debug your application and you should find the statement that is causing the problem and will probably be able to resolve it yourself.  Good luck.  . 

Please use plain text.
Developer
simon_hain
Posts: 15,900
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Background with custom layout error

hard to say, my crystal ball is all cloudy. maybe a code snippet could enlighten us?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Background with custom layout error

Does "custom layout" mean overriding a Manager's sublayout? Are you using the abstract Manager class as a base or are you modifying a built-in one such as HorizontalFieldManager?

 

Please show at least your custom Manager's definiton, especially your sublayout override and we might be able to help.

 

As a separate issue: I believe MainScreen has its own share of bugs when you are talking about the background. Be careful where you set that background. If it is at the MainScreen level, move it down the line, to some VerticalFieldManager enveloping the rest of your UI components.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
New Developer
praveensingh18
Posts: 13
Registered: ‎02-10-2012
My Device: Curve 9300 3G
My Carrier: CellC

Re: Background with custom layout error

 

I create a class called MyDefaultScreen to set the background image, then I create a class Signs that extends MyDefaultScreen and adds the custom layout and components. My CustomHManager is my custom layout, I have tried to extend HFM and Manager class but both gives the same error.

 

I'm trying to create a layout with a button on the left side, label in the center and button on right side.

 

 

==================================================

MyDefaultScreen Class   - Just adds a background image

==================================================

import net.rim.device.api.system.Bitmap;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

 

public class MyDefaultScreen extends MainScreen {

 

  /**
  * Constructor MyDefaultScreen(String title)
  *
  * @param title
  */

 

  public MyDefaultScreen() { 

    Bitmap _bm = Bitmap.getBitmapResource("splashscreen.png");
    Background _bg = BackgroundFactory.createBitmapBackground(_bm,
    Background.POSITION_X_LEFT, Background.POSITION_Y_TOP, 
    Background.REPEAT_SCALE_TO_FIT);
    VerticalFieldManager _scrMngr = (VerticalFieldManager) getMainManager();
    _scrMngr.setBackground(_bg);

  }

}

 

 

==================================================

Signs Screens - extends MyDefaultScreen

==================================================

import net.rim.device.api.ui.component.ButtonField;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

 

public class Signs extends MyDefaultScreen{

  public Signs(){

    setTitle("Signs");
    CustomHManager h1 = new CustomHManager();
    ButtonField cbf1 = new ButtonField("<<");
    ButtonField cbf2 = new ButtonField(">>");
    LabelField lbl1 = new LabelField("Sign");
    h1.add(cbf1);
    h1.add(lbl1);
    h1.add(cbf2);
    add(h1);
  }

}

 

 

==================================================

CustomHManager - Custom Layout Manager

==================================================

import net.rim.device.api.ui.Field;

import net.rim.device.api.ui.Manager;

 

public class CustomHManager extends Manager {

  public CustomHManager() {
    super(Manager.NO_HORIZONTAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR);
  }

 

  public int getPreferredWidth() {
    int width = 0;
    int numberOfFields = getFieldCount();
    for (int i = 0; i < numberOfFields; i++) {
      width += getField(i).getPreferredWidth();
    }
    return width;

    // return Display.getWidth();
  }


  public int getPreferredHeight() {

    int height = 0;

    int numberOfFields = getFieldCount();
 

    for (int i = 0; i < numberOfFields; i++) {

      height += getField(i).getPreferredHeight();
    }
    return height;

}

 

  protected void sublayout(int width, int height) {

    Field field;

    field = getField(0);

    layoutChild(field, width, height);
    setPositionChild(field, 0, 10);

    field = getField(1);
    layoutChild(field, width, height);
    setPositionChild(field, (width / 2) - (field.getPreferredWidth() / 2), 20);

    field = getField(2);
    layoutChild(field, width, height);
    setPositionChild(field, width - (field.getPreferredWidth() + 10), 10);

    setExtent(width, height);
  }

 

}

 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Background with custom layout error

Nothing that would immediately scream out "Fix me!"

 

However:

1. Your CustomManager behaves as though USE_ALL_HEIGHT | USE_ALL_WIDTH were always in effect. Is that what you really want?

2. layoutChild calls - are you sure each field has the whole width and height available? Because that's what you are telling them. If you are going to position field0 at (0, 10), at least tell it to use height - 10 instead of height.

3. Using getPreferred(Width/Height) for position calculations after you've laid out the field and can ask it about its actual width/height is not flexible enough. Consider using getWidth/getHeight in those setPositionChild calls.

 

And, as Peter suggested, run it in debugger with breakpoint on the exception. Once it occurs, take a look at the failing statement and see what's wrong there. Send the information here if still in doubt.

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
New Developer
praveensingh18
Posts: 13
Registered: ‎02-10-2012
My Device: Curve 9300 3G
My Carrier: CellC

Re: Background with custom layout error

Hi 

 

I ran my app with debugging and here is a screenshot of the debug window when my app gets stuck.

 

 

Screenshot.PNG

 

I seemed to have fixed the problem now my custom layout and and background displays correctly, I changed my background not to scale to fit, can anyone help explain what when wrong when using Background.REPEAT_SCALE_TO_FIT

 

Bitmap _bm = Bitmap.getBitmapResource("splashscreen.png");
Background _bg = BackgroundFactory.createBitmapBackground(_bm,
Background.POSITION_X_LEFT, Background.POSITION_Y_TOP,
Background.REPEAT_SCALE_TO_FIT);
VerticalFieldManager _scrMngr = (VerticalFieldManager) getMainManager();
_scrMngr.setBackground(_bg);

 

 

Bitmap _bm = Bitmap.getBitmapResource("splashscreen.png");
Background _bg = BackgroundFactory.createBitmapBackground(_bm,
Background.POSITION_X_LEFT, Background.POSITION_Y_TOP,
Background.REPEAT_NONE);
VerticalFieldManager _scrMngr = (VerticalFieldManager) getMainManager();
_scrMngr.setBackground(_bg);

Please use plain text.