Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:41:41+00:00 2026-06-17T16:41:41+00:00

I created this method to take in a URL, retrieve the PNG file from

  • 0

I created this method to take in a URL, retrieve the PNG file from that URL, compress it, and save it to the SD card. The method then gets that file and uses it as a sprite on the Live Wallpaper.

        try
        {
            URL url = new URL(
                    "http://www.google.com/someimage.png");
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            webBitmap = BitmapFactory.decodeStream(input);

            f = new File(Environment.getExternalStorageDirectory()
                    .getAbsolutePath() + "/webbitmap.png");

            // Save the bitmap to the sdcard.
            String filepath = Environment.getExternalStorageDirectory()
                    .getAbsolutePath();
            FileOutputStream fos = new FileOutputStream(filepath + "/"
                    + "webbitmap.png");
            webBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.flush();
            fos.close();

            if (f.exists())
            {

                BitmapTextureAtlas texture = new BitmapTextureAtlas(512,
                        1024, TextureOptions.BILINEAR);

                FileBitmapTextureAtlasSource fileTextureSource = new FileBitmapTextureAtlasSource(
                        f);
                TextureRegion textureRegion = TextureRegionFactory
                        .createFromSource(texture, fileTextureSource, 0, 0,
                                true);
                this.mEngine.getTextureManager().loadTexture(texture);

                webSprite = new Sprite(512, 1024, 320, 634,
                        textureRegion);
                webSprite.setPosition(
                        mCamera.getCenterX()
                                - webSprite.getRotationCenterX(),
                        mCamera.getCenterY()
                                - webSprite.getRotationCenterY());
                scene.attachChild(webSprite);
            }
            else
            {
                scene.attachChild(GTMessage);

            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch(IllegalArgumentException e)
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

For the most part it is working great. However, occasionally when this method is run an IllegalArgumentException (Error loading bitmap) occurs on this line:

webBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

Here is the stack trace:

01-24 12:50:52.739: E/AndEngine(19411): Error loading: FileBitmapTextureAtlasSource(/mnt/sdcard/webbitmap.png)
01-24 12:50:52.739: E/AndEngine(19411): java.lang.IllegalArgumentException: FileBitmapTextureAtlasSource: FileBitmapTextureAtlasSource(/mnt/sdcard/webbitmap.png) returned a null Bitmap.
01-24 12:50:52.739: E/AndEngine(19411):     at org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTextureToHardware(BitmapTextureAtlas.java:159)
01-24 12:50:52.739: E/AndEngine(19411):     at org.anddev.andengine.opengl.texture.Texture.loadToHardware(Texture.java:116)
01-24 12:50:52.739: E/AndEngine(19411):     at org.anddev.andengine.opengl.texture.TextureManager.updateTextures(TextureManager.java:146)
01-24 12:50:52.739: E/AndEngine(19411):     at org.anddev.andengine.engine.Engine.onDrawFrame(Engine.java:503)
01-24 12:50:52.739: E/AndEngine(19411):     at org.anddev.andengine.opengl.view.RenderSurfaceView$Renderer.onDrawFrame(RenderSurfaceView.java:154)
01-24 12:50:52.739: E/AndEngine(19411):     at com.*****.*****.GLThread.guardedRun(GLThread.java:236)
01-24 12:50:52.739: E/AndEngine(19411):     at com.*****.*****.GLThread.run(GLThread.java:95)

Is there anyway to at least prevent this force close from occuring? Or if there was a way to fix it for good that would be ideal.

Thank you

//EDIT – My Solution

After researching where the exception is thrown, I found out it is being thrown in the BitmapTextureAtlas.java class. Specifically this line:

if(bitmap == null) 
{
  throw new IllegalArgumentException(bitmapTextureSource.getClass().getSimpleName() + ": " + bitmapTextureSource.toString() + " returned a null Bitmap.");
}

I found out that the bitmap was not actually null, it seemed to just be “corrupted”. This was due to the fact that the file already existed and it was in the process of overwriting it. This is how I fixed the issue:

f = new File(Environment.getExternalStorageDirectory()
                        .getAbsolutePath() + "/webbitmap.png");
if (f.exists())
{
   f.delete();
}

I no longer receive the error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:41:42+00:00Added an answer on June 17, 2026 at 4:41 pm

    You can use throws IllegalArgumentException in the class which has this snippet.

    Look here for more details
    http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/IllegalArgumentException.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've started using a WebRequest to retrieve a file from a given URL. If
I have a custom field I have created that loads images from a url.
I'v created a Contentprovide and implements it's update() method like this: @Override public int
Can a custom event be created for any object method? To do this do
I'd like to use this method to create user-friendly URL. Because my site is
I have created a WCF Service and then after consuming this service in J2ME.
I have a method that pulls a url name(varchar), a urlID(int) and its Enabled
I would like to create a model method that will take the user (which
I have files on a server that can be accessed from a URL formatted
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.