Reputation: 528
I know there are many questions relating to this question, but few appear to be for openGL.
I'm trying to load some PNG files from the assets folder into a Bitmap, but for some reason the returned Bitmap is null which in turn throws a NullPointerException here:
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
The code I am using to load the image from the assets folder:
public static Bitmap getBitmapFromAsset(AssetManager mgr, String path)
{
InputStream is = null;
Bitmap bitmap = null;
try {
is = mgr.open(path);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
bitmap = BitmapFactory.decodeStream(is, null, options);
}
catch (final IOException e)
{
bitmap = null;
Log.e(TAG, "FAILED TO get getBitmapFromAsset: " + e.getMessage());
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException ignored)
{
}
}
}
return bitmap;
}
I've tried it a few different ways, e.g without the BitmapFactory.Options, but no matter what I am getting the NullPointerException, so I'm guessing there's another procedure I should be doing.
P.S. I can load them from the res/raw folder, but I can't have subdirectories to organise my assets.
Upvotes: 1
Views: 1147
Reputation: 528
OK, I just realised that my assets folder was under the res folder for some reason. I just put it under the main folder app/main/assets and it's working. *blushes
Upvotes: 1