我正在尝试在我的黑莓应用程序中添加一个地图字段,但是我在导航到该屏幕时遇到异常,说明IllegalArgumentException(Bitmap太大)。有什么想法吗?
代码:
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.MapField
和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
答案 0 :(得分:1)
IllegalArgumentException: Bitmap is too large
意味着在RIM内部代码中的某个地方尝试创建一个非常大的Bitmap
实例。什么是“真正的大”只知道RIM - 这个不幸的是没有明确的文件。
因此,不涉及此问题的一般规则是以某种方式控制/限制Bitmap
实例的维度。请注意,要解决此问题,您甚至不需要显式创建Bitmap
实例,因为在您的情况下,它足以创建一些暗示Bitmap
使用的其他内容。当你显示/绘制/绘制smth时,即使你没有明确地创建它,也会使用Bitmap
。
根据您发布的代码,我怀疑这一行可能会导致问题:
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);