0

我正在尝试在我的黑莓应用程序中添加地图字段,但在导航到该屏幕时出现异常,提示 IllegalArgumentException(位图太大)。任何想法?

代码:

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);
                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));
    }
}

例外:

[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:我也对net.rim.device.api.lbs.maps.ui.MapFieldand的使用感到困惑net.rim.device.api.lbs.MapField

更新:

我按照您的建议进行了尝试,但仍然抛出相同的错误。我注意到一件奇怪的事情。更新后的代码如下:

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());

但在日志中我没有看到参数集。日志显示:

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

1 回答 1

1

IllegalArgumentException: Bitmap is too large意味着在 RIM 内部代码的某个地方,有人试图创建一个非常大的Bitmap实例。什么是“真正的大”只有 RIM 知道——不幸的是,没有关于这方面的明确文档。

因此,不涉及此问题的一般规则是以某种方式控制/限制Bitmap实例的尺寸。请注意,要解决这个问题,您甚至不需要显式创建一个Bitmap实例,因为在您的情况下,创建一些其他暗示Bitmap使用的东西就足够了。绝对当您显示/绘制/绘画时,Bitmap即使您没有明确创建它,也会使用 a 。

从您发布的代码中,我怀疑这一行可能会导致问题:

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

你知道实际上传递给MapField构造函数的参数是什么吗?要测试这个猜测,你可以试试这个:

int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
basicMapField = new MapField(displayWidth / 2, displayHeight / 2);
于 2011-04-02T07:40:04.470 回答