简体   繁体   中英

Android app crashes due to large number of images

I'm writing an app that will require about 520 small png's. I've stored these in my assets folder and I access them using getAssets().

However my app crashes at startup and works OK if I reduce the number of images in the folder. Is it possible to store additional images somewhere else or to increase the size of images that my app can handle?

My logcat error is "Failed adding to JNI local ref table (has 512 entries)"

each image is about 4kb large, the total folder size is 2.1 Mb

The relevant code is:

        AssetManager assets = getAssets();
    fileNameList = new ArrayList<String>();
    fileNameList.clear();

    String[] paths;
    try {
        paths = assets.list("final");

        for (String path : paths)
            fileNameList.add(path.replace(".jpg", ""));

    } catch (IOException e) {
        Log.e(TAG, "Error loading image file names", e);
    } // end catch

I think your answer is in this post . You cannot expand the reference table beyond 512 items so you need to delete local references to class and/or objects to free up space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM