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

  • Home
  • SEARCH
  • 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 6800067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:55:27+00:00 2026-05-26T18:55:27+00:00

I have gone through following links enter link description here enter link description here

  • 0

I have gone through following links

enter link description here

enter link description here

and i have followed the following tutorial to do cache the images after loading it from server

enter link description here

and my code segment is :

private Bitmap getBitmap(String url) {
//      PhotoToLoad photoToLoad = new PhotoToLoad(url, new ImageView(a));
//      String filename = photoToLoad.url;
        //String filename = url;
        String filename = String.valueOf(url.hashCode());
        Log.v("TAG FILE :", filename);
        File f = new File(cacheDir, filename);
        // Is the bitmap in our cache?
        Bitmap bitmap = BitmapFactory.decodeFile(f.getPath());
        if (bitmap != null)
            return bitmap;
        else {
            // Nope, have to download it
            try {
                bitmap = BitmapFactory.decodeStream(new URL(url)
                        .openConnection().getInputStream());
                // save bitmap to cache for later
                writeFile(bitmap, f);
                return bitmap;
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
                Log.v("FILE NOT FOUND", "FILE NOT FOUND");
                return null;
            }catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
                return null;
            }
        }
    }

    private void writeFile(Bitmap bmp, File f) {
        FileOutputStream out = null;

        try {
            out = new FileOutputStream(f);
            bmp.compress(Bitmap.CompressFormat.PNG, 80, out);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null)
                    out.close();
            } catch (Exception ex) {
            }
        }
    }

I am getting FileNotFoundException :

11-12 15:19:25.495: VERBOSE/cacheDir(266): /sdcard/data/BalajeeBazaar

11-12 15:19:26.035: VERBOSE/TAG FILE :(266): -951166081

11-12 15:19:26.315: WARN/System.err(266): java.io.FileNotFoundException: /sdcard/data/BalajeeBazaar/-951166081

11-12 15:19:26.315: WARN/System.err(266):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:231)

11-12 15:19:26.315: WARN/System.err(266):     at java.io.FileOutputStream.<init>(FileOutputStream.java:96)

11-12 15:19:26.315: WARN/System.err(266):     at java.io.FileOutputStream.<init>(FileOutputStream.java:69)

11-12 15:19:26.315: WARN/System.err(266):     at com.ecommerce.balajeebazaar.CacheImages.writeFile(CacheImages.java:160)

11-12 15:19:26.315: WARN/System.err(266):     at com.ecommerce.balajeebazaar.CacheImages.getBitmap(CacheImages.java:142)

11-12 15:19:26.315: WARN/System.err(266):     at com.ecommerce.balajeebazaar.CacheImages.access$0(CacheImages.java:125)

11-12 15:19:26.315: WARN/System.err(266):     at com.ecommerce.balajeebazaar.CacheImages$PhotosLoader.run(CacheImages.java:77)

11-12 15:19:26.325: WARN/dalvikvm(266): threadid=17: thread exiting with uncaught exception (group=0x4001aa28)

11-12 15:19:26.325: ERROR/AndroidRuntime(266): Uncaught handler: thread Thread-10 exiting due to uncaught exception

11-12 15:19:26.325: ERROR/AndroidRuntime(266): java.lang.ClassCastException: android.graphics.Bitmap

11-12 15:19:26.325: ERROR/AndroidRuntime(266):     at com.ecommerce.balajeebazaar.CacheImages$PhotosLoader.run(CacheImages.java:79)

Please guide me how to resolve this ?

Thanks~

  • 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-05-26T18:55:28+00:00Added an answer on May 26, 2026 at 6:55 pm

    Are you properly defining the directory name?

    Maybe you didn’t declare the directory name properly…

    So, can you please check that it’s all right ??

     //Find the dir to save cached images
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"YourDirectoryName");
        else
            cacheDir=context.getCacheDir();
        if(!cacheDir.exists())
            cacheDir.mkdirs();
    }
    

    Check your class and make sure your path is right or anything else and tell me after.

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

Sidebar

Related Questions

I have gone through the following tutorial : http://www.javaworld.com/community/node/2915 And after reading the above
I followed this guide here perfectly and have gone through it again but when
I have been learning MVVM / WPF and have gone through the tutorial here
I have gone through following question. Convert NSString to NSDictionary It is something different
I have downloaded sample code from Apple Center.I also have gone through following question:
What could be the understanding of the following? I have gone through this post
I have gone through the following question. Objective C - Where do you dealloc
I have gone through this question that shows the following code: -(NSString *)tableView:(UITableView *)tableView
I have gone through the following article regarding the logging frameworks available for Java:
I have gone through many questions asked here and on other forums regarding @property

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.