1

我有一个图像数组及其相应的标题:

int [] landmarkImages={R.drawable.oblation,R.drawable.eastwood,R.drawable.ecopark,R.drawable.circle};


String []landmarkDetails = { "Oblation", "Eastwood", "Ecopark", "QC Circle"};

我是使用 Bitmap 功能的新手,我不知道如何处理这个问题。Activity 强制停止并显示java.lang.OutofMemoryError 现在我想将它们插入到我的 sqlite 数据库中,但是在这一行出现错误:

Bitmap image = BitmapFactory.decodeResource(getResources(),
                landmarkImages[loaded]);

这是它所在的方法:

Log.d("Insert: ", "Inserting ..");


    for(int loaded=0; loaded <=landmarkDetails.length;loaded++){

        Bitmap image = BitmapFactory.decodeResource(getResources(),
                landmarkImages[loaded]);

        // convert bitmap to byte
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte imageInByte[] = stream.toByteArray();
        Log.d("Going to load images", "Image "+ loaded);

        Log.d("Goind to load objects", "loading");
        int ctr = db.checkContact(landmarkDetails[loaded]);
        if(ctr == 0){
            Log.d("Nothing Loaded", "Loading Now");
            db.addContact(new Contact(landmarkDetails[loaded], imageInByte));}
            Log.d(landmarkDetails[loaded], "Loaded!");
    }
4

0 回答 0