开发者

Displaying MapField inside the application throws IllegalArgumentException Bitmap is too large exception

I'm trying to add a map field in my blackberry application, but I get an exception on navigating to that screen saying IllegalArgumentException(Bitmap is too large). Any Idea?

Code:

package com.quadrazol.bb.fpg.screens.maps;

import net.rim.device.api.lbs.maps.ui.MapField;
import net.rim.device.api.lbs.maps.model.MapDataModel;
import net.rim.device.api.lbs.maps.model.MapLocation;
import net.rim.device.api.lbs.maps.model.Mappable;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.quadrazol.bb.fpg.screens.TabScreen;
import com.quadrazol.bb.fpg.util.DataHelper;
import com.quadrazol.bb.fpg.util.UIHelper;

public class FindAPlannerScreen extends TabScreen {

    private MapField basicMapField;

    public FindAPlannerScreen() {
        super();
        VerticalFieldManager mgr = new VerticalFieldManager(
                VerticalFieldManager.USE_ALL_HEIGHT
                        | VerticalFieldManager.USE_ALL_WIDTH
                        | VerticalFieldManager.NO_VERTICAL_SCROLL) {
            public void paint(Graphics graphics) {
                graphics.setBackgroundColor(Color.BLACK);
                graphics.clear();
                super.paint(graphics);
            }
        };
        add(mgr);
        mgr.add(UIHelper.generateHeader());
        mgr.add(new SeparatorField() {
            public void paint(Graphics graphics) {
                graphics.setColor(Color.WHITE);
  开发者_JS百科              super.paint(graphics);
            }

        });

        VerticalFieldManager mainScrollView = UIHelper.generateMainScrollView();
        basicMapField = new MapField(mainScrollView.getWidth()-6,(int) (mainScrollView.getHeight()*.90));
        MapDataModel model = basicMapField.getModel();
        Mappable[] plannerDetails = DataHelper.fetchPlannerDetails();
        if (plannerDetails != null) {
            model.addAll(plannerDetails);
        }

        mainScrollView.add(basicMapField);
        mgr.add(mainScrollView);

        mgr.add(UIHelper.generateTabBarForScreen(UIHelper.TAB_MAP));
    }
}

Exception:

[0.0] ViewEngine$RenderingEngine:unknown exception occured, IllegalArgumentException(Bitmap is too large)
[0.0] IllegalArgumentException
[0.0] Bitmap is too large
[0.0] net_rim_cldc-10(4C48DD41)
[0.0]  Bitmap
[0.0]  <init>
[0.0]  0x8778
[0.0] net_rim_cldc-10(4C48DD41)
[0.0]  Bitmap
[0.0]  <init>
[0.0]  0x8628
[0.0] net_rim_cldc-10(4C48DD41)
[0.0]  Bitmap
[0.0]  <init>
[0.0]  0x8609
[0.0] net_rim_cldc-10(4C48DD41)
[0.0]  Bitmap
[0.0]  <init>
[0.0]  0x85ED
[0.0] net_rim_cldc-10(4C48DD41)
[0.0]  Bitmap
[0.0]  <init>
[0.0]  0x859E
[0.0] net_rim_bb_maps_api-4(4C48E231)
[0.0]  ViewEngine
[0.0]  generateContext
[0.0]  0x6457
[0.0] net_rim_bb_maps_api-4(4C48E231)
[0.0]  ViewEngine$RenderingEngine
[0.0]  <private>
[0.0]  0x65F2
[0.0] net_rim_bb_maps_api-4(4C48E231)
[0.0]  ViewEngine$RenderingEngine
[0.0]  run
[0.0]  0x6507

PS: I'm also confused between usage of net.rim.device.api.lbs.maps.ui.MapField and net.rim.device.api.lbs.MapField

Update:

I tried as per your suggestion, but still it is throwing the same error. I noticed one strange thing. The updated code is as follows:

int displayWidth = Display.getWidth();
        int displayHeight = Display.getHeight();
        basicMapField = new MapField(displayWidth / 2, displayHeight / 2);
        System.out.println("Display Dimen:"+displayHeight+" "+displayWidth);
        System.out.println("Map Dimen:"+basicMapField.getHeight()+" "+basicMapField.getWidth());

But in logs I dont see the parameters set. The logs shows:

[0.0] Display Dimen:480 360
[0.0] Map Dimen:0 0


IllegalArgumentException: Bitmap is too large means that somewhere inside of the RIM's internal code there was an attempt to create a really big Bitmap instance. What is "really big" knows only RIM - there's no clear documentation on this unfortunatelly.

So a general rule not to get in this issue is to somehow control/restrict the dimentions of the Bitmap instance. Note, to get into the issue you don't even need to explicitly create a Bitmap instance, as in your case it is just enough to create some other stuff that implies Bitmap usage. Definitely when you show/draw/paint smth, then a Bitmap is used even if you don't create it explicitly.

From the code you posted I suspect this line may cause the issue:

basicMapField = new MapField(mainScrollView.getWidth()-6,
                        (int) (mainScrollView.getHeight()*.90));

Do you know what arguments are actually passed to MapField constructor? To test this guess could you try this:

int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
basicMapField = new MapField(displayWidth / 2, displayHeight / 2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜