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 8354443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:33:00+00:00 2026-06-09T09:33:00+00:00

i have a listview that shows diferent data from my database. this works perfeclty.

  • 0

i have a listview that shows diferent data from my database. this works perfeclty. however i can only have 3 items in my list becouse i run out of memory since im loading the full images. this is the code i have now that is working, but gives out of memory when more then three list items are in the list.

  String[] from = new String[] { "NAME", "DATE", "WEIGHT", "IMAGE_PATH"};      
  int[] to = new int[] { R.id.name, R.id.date, R.id.weight, R.id.list_image};
  contactAdapter = new SimpleCursorAdapter(
     Mylistview.this, R.layout.list_row, null, from, to);
  setListAdapter(contactAdapter);

what i want to do is shrink the images to 72×72 before loading them in the list. Below is a code that is not working the way i want, but it gives you an idea of what i want 🙂

  list_image = (ImageView) findViewById(R.id.list_image);


  String[] from = new String[] { "NAME", "DATE", "WEIGHT", "IMAGE_PATH"};      
  int[] to = new int[] { R.id.name, R.id.date, R.id.weight};
  contactAdapter = new SimpleCursorAdapter(
     Mylistview.this, R.layout.list_row, null, from, to);
  setListAdapter(contactAdapter); 

 String icon = "IMAGE_PATH"

  Bitmap bmp = BitmapFactory.decodeStream(icon);        
  Bitmap bm = Bitmap.createScaledBitmap(bmp, 72, 72, false);
  list_image.setImageBitmap(bm);

i want the String icon to get the image path from “IMAGE_PATH” that is loaded from the database in the string array.

is there a way to do this, or do i need to find other ways to populate my listview with both images and small icons? perhaps when i take a picture i should save the image in two places. one real image and one icon and put the icon path to the database?

thank you

This is the code and the error code after doing what Vishva Patel helped with.

       BitmapScaler scaler = null;
try {
    scaler = new BitmapScaler(new File("IMAGE_PATH"), 72);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
  list_image.setImageBitmap(scaler.getScaled());

 08-08 22:23:15.973: E/AndroidRuntime(2947): FATAL EXCEPTION: main
 08-08 22:23:15.973: E/AndroidRuntime(2947): java.lang.RuntimeException: Unable to  start activity   ComponentInfo{se.xflash.myapp/se.xflash.myapp.myapp}:     java.lang.RuntimeException: Unable to start activity  ComponentInfo{se.xflash.myapp/se.xflash.myapp.MyNames}:    java.lang.NullPointerException
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.os.Handler.dispatchMessage(Handler.java:99)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.os.Looper.loop(Looper.java:137)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread.main(ActivityThread.java:4507)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at java.lang.reflect.Method.invokeNative(Native Method)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at java.lang.reflect.Method.invoke(Method.java:511)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at dalvik.system.NativeStart.main(Native Method)
 08-08 22:23:15.973: E/AndroidRuntime(2947): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{se.xflash.myapp/se.xflash.myapp.MyNames}: java.lang.NullPointerException
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1809)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.widget.TabHost.setCurrentTab(TabHost.java:346)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.widget.TabHost.addTab(TabHost.java:236)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at se.xflash.myapp.myapp.onCreate(myapp.java:45)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.Activity.performCreate(Activity.java:4465)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at      android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    ... 11 more
 08-08 22:23:15.973: E/AndroidRuntime(2947): Caused by: java.lang.NullPointerException
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at se.xflash.myapp.BitmapScaler.<init>(BitmapScaler.java:42)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at se.xflash.myapp.MyNames.onCreate(MyNames.java:56)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.Activity.performCreate(Activity.java:4465)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
 08-08 22:23:15.973: E/AndroidRuntime(2947):    ... 21 more
  • 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-09T09:33:02+00:00Added an answer on June 9, 2026 at 9:33 am

    1.) The easiest solution would be to use the class mentioned in this blogpost BitmapScaler.java : http://zerocredibility.wordpress.com/2011/01/27/android-bitmap-scaling/ , it works excellently and solves the out of memory exception issue. All you have to do is provide the file where your image is saved as a parameter to the constructor along with the scaled width that you want (72 in your case). Here’s the code you’d have to use in your specific case:

    BitmapScaler scaler = new BitmapScaler(new File("IMAGE_PATH"), 72);
    list_image.setImageBitmap(scaler.getScaled());
    

    2.) Yes, one of the solutions would be to scale the bitmap when you take the picture and save it as icon-yourimagename.jpg along with your original image (if you need the original size image that you took)

    3.) Use bm.recycle() once your have assigned bm to your list_image to ensure that the bitmaps are garbage collected and that some memory is freed. This MIGHT fix the memory error.

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

Sidebar

Related Questions

I have a ListView that shows around 300 items. When something is changed and
I have ListView that uses a GridView to display several columns of data. Two
I have a ListView that shows a list of names. When you select a
I have an ObservableCollection of class Customers that I fill from a database query.
I have an array that successfully shows as a listview as the main activity.
I'm developing an App, that shows a ListView with 30 items. In each row,
I have this XML file from which I'm grabbing all the data: <?xml version=1.0
i have a TabLayout that has a ListView to show as intent. I would
I have a WPF App that implements a ListView. I would like to show
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton

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.