Null-pointer issue displaying an image from assets folder Android 2.2 SDK

后端 未结 2 342
耶瑟儿~
耶瑟儿~ 2021-01-28 13:34

I looked at the 2 examples on Stack, but can\'t get them to work. I\'m simply trying to grab an image from a folder in assets and set it as in ImageView, but get a null pointer

2条回答
  •  被撕碎了的回忆
    2021-01-28 14:25

    Where is "file:///android_asset/Samples/" + imageName coming from? If your hierarchy looks like assets/file_name.jpg, you would just call open(file_name.jpg). In other words, try replacing your file:///android_asset/Samples/" + imageName with just imageName.

    Check out the API Demos, specifically the ReadAsset.java class:

    try {
            InputStream is = getAssets().open("read_asset.txt");
    

    ...

    where the assets folder looks like

    alt text

提交回复
热议问题