使用MapContainer的OutOfMemoryError

时间:2019-01-28 21:18:45

标签: codenameone

在我的初始屏幕之后,我的主窗体包含一个MapContainer,在其中显示几个点。它在Simulator上运行良好。但是,在设备上,几秒钟后,电话仅挂起,应用程序崩溃。这与我添加多个点的方式有关系吗?我已经显示了下面的代码。我还添加了LogCat stackTrace。

public void addMarkers(MapContainer mc)
   {
       Vector v=  new Vector();
       try
       {
        Style s = new Style();
        s.setFgColor(0xff0000);
        s.setBgTransparency(0);
        FontImage markerImg = FontImage.createMaterial(FontImage.MATERIAL_PLACE, s, 7);
        EncodedImage ei = EncodedImage.createFromImage(markerImg, false);
        List lx = (List) Storage.getInstance().readObject("CASES");
        Coord c = null;
       for(Object m: lx)
       {
           Map p= (Map) m;
           c = new Coord(Double.parseDouble(p.get("latitude").toString()), Double.parseDouble(p.get("longitude").toString()));
           v.add(c);
           mc.addMarker(ei, c, "Hi marker", "Optional long description", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    ToastBar.showMessage("You clicked the marker", FontImage.MATERIAL_PLACE);
                }
            });
       }
       mc.fitBounds(BoundingBox.create(v));

       }catch(Exception er){er.printStackTrace();}       
   }

下面是我的LogCat strackTrace

01-29 00:06:24.407 21924-22089/com.jajitech.mobile.creporter E/AndroidRuntime: FATAL EXCEPTION: androidmapsapi-Snapshot
    Process: com.jajitech.mobile.creporter, PID: 21924
    java.lang.OutOfMemoryError: Failed to allocate a 1831692 byte allocation with 48112 free bytes and 46KB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.Bitmap.nativeCreate(Native Method)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:975)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
        at com.google.maps.api.android.lib6.impl.a.b(:com.google.android.gms.dynamite_mapsdynamite@14366045@14.3.66 (040304-213742215):9)
        at com.google.maps.api.android.lib6.impl.bk.run(:com.google.android.gms.dynamite_mapsdynamite@14366045@14.3.66 (040304-213742215):4)
        at java.lang.Thread.run(Thread.java:818)

0 个答案:

没有答案