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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:03:02+00:00 2026-05-25T23:03:02+00:00

I’m working on a project which communicate with web server and download some photos.

  • 0

I’m working on a project which communicate with web server and download some photos. I want these photos to be shown on a listview after the download,but it’s throwing me a NullPointerException. Here is the code I’m using :

   private ArrayList <HashMap<String, Object>> items;
    private static final String NAMEKEY = "bookname";
    private static final String INFOKEY = "bookprice";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mystampii_layout);
    }
        });

        ListView listView = (ListView)findViewById(R.id.mystampii_listview);
        items = new ArrayList<HashMap<String,Object>>();
        HashMap<String, Object> hm;


        final Bitmap b = BitmapFactory.decodeFile("/sdcard/MediaCard2a44bb1f782925923195ee546e7ef395.jpg", null);
        ImageView brum = (ImageView) findViewById(R.id.main_img);
        brum.setImageBitmap(b);


        hm = new HashMap<String, Object>();
        hm.put(NAMEKEY, "Moto GP 2010");
        hm.put(INFOKEY, "98 Stampii");
        items.add(hm);

          // Define SimpleAdapter and Map the values with Row view R.layout.listbox
           SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.main_listview,
                    new String[]{NAMEKEY,INFOKEY}, new int[]{R.id.main_img,R.id.main_name, R.id.main_info});

            listView.setAdapter(adapter);
            listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

I know, why I’m getting NullPointerException : because my ImageView brum is placed in R.layout.main_listview and I’m setting as Content on this activity R.layout.mystampii_layout. I really can get the idea how to set the Image from SDCard to a ImageView from another layout.

Any suggestions how can I do that, or how can I show the downloaded image from SDCard in listview.

Thanks really for any kind of help!!!

  • 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-25T23:03:02+00:00Added an answer on May 25, 2026 at 11:03 pm

    Create your custom Adapter like this :

    import java.util.ArrayList;
    
    import com.stampii.stampii.R;
    import com.stampii.stampii.comm.rpc.CollectionRPCPacket;
    import com.stampii.stampii.comm.rpc.UserDatabaseHelper;
    
    import android.app.Activity;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class MyArrayAdapter extends ArrayAdapter<String> {
        private final Activity context;
        private final String[] names;
        CollectionRPCPacket rpcPacket;
        Cursor cursor;
        String title;
    
        public MyArrayAdapter(Activity context, String[] names) {
            super(context, R.layout.main_listview, names);
            this.context = context;
            this.names = names;
        }
    
        // static to save the reference to the outer class and to avoid access to
        // any members of the containing class
        static class ViewHolder {
            public ImageView imageView;
            public TextView textView,textView2;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // ViewHolder will buffer the assess to the individual fields of the row
            // layout
    
            ViewHolder holder;
            // Recycle existing view if passed as parameter
            // This will save memory and time on Android
            // This only works if the base layout for all classes are the same
            View rowView = convertView;
            if (rowView == null) {
                LayoutInflater inflater = context.getLayoutInflater();
                rowView = inflater.inflate(R.layout.main_listview, null, true);
                holder = new ViewHolder();
                holder.textView = (TextView) rowView.findViewById(R.id.main_name);
                holder.textView2 = (TextView) rowView.findViewById(R.id.main_info);
                holder.imageView = (ImageView) rowView.findViewById(R.id.main_img);
                rowView.setTag(holder);
            } else {
                holder = (ViewHolder) rowView.getTag();
            }
            final Bitmap b = BitmapFactory.decodeFile("/sdcard/MediaCard2a44bb1f782925923195ee546e7ef395.jpg", null);
    
    
            holder.textView.setText();
            holder.textView2.setText("");
            holder.imageView.setImageBitmap(b);
    
    
            return rowView;
        }
    }
    

    And you can use it like this on your activity :

    ListView lv1 = (ListView)findViewById(R.id.listViewOne);
    String[] names = new String[] { "ONE", "TWO", "THREE"};
    lv1.setAdapter(new MyArrayAdapter(this, names));
    

    Hope it helps!

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

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.