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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:39:08+00:00 2026-05-26T07:39:08+00:00

I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).

  • 0

I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).
I try to set images with text using grid view and Layout Inflater.I also did debuging process but still I am not able to get solution.Please check the following code.

public class CategoryAdapter extends BaseAdapter {
private Context mContext;
public static final int ACTIVITY_CREATE = 10;
int id=-1;
public CategoryAdapter(Context c) {
        mContext = c;
 }
public int getCount() {
    return CategorylogoActivity.logoarray.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
       Bitmap bm=null;
       ImageView iv = null ;
       TextView tv=null;
       View v;
                    if(convertView==null){

                        @SuppressWarnings("static-access")
                        LayoutInflater li = (LayoutInflater)mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);  

                        v = li.inflate(R.layout.category_icon, null);
                        tv= (TextView)v.findViewById(R.id.icon_text);

                        iv = (ImageView)v.findViewById(R.id.icon_image);


                    }
                    else
                    {
                        v = convertView;
                    }
                        try {
                            URL aURL = new URL(CategorylogoActivity.logoarray[position]);
                            URLConnection conn = aURL.openConnection();
                            conn.connect();
                            InputStream is = conn.getInputStream();
                            // Buffered is always good for a performance plus. 
                            BufferedInputStream bis = new BufferedInputStream(is);
                            // Decode url-data to a bitmap. 
                            bm = BitmapFactory.decodeStream(bis);

                            bis.close();
                            is.close();
                        } catch (MalformedURLException e) {

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

                            e.printStackTrace();
                        }
                     iv.setImageBitmap(bm);
                    tv.setText(CategorylogoActivity.namearray[0]);

                    return v;
  • 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-26T07:39:09+00:00Added an answer on May 26, 2026 at 7:39 am
    static class viewHolder {
           ImageView iv = null ;
           TextView tv=null;
    }
    
    
    public View getView(int position, View convertView, ViewGroup parent) {
           Bitmap bm=null;
           viewHolder vh;
           View v;
                        if(convertView==null){
                            vh = new viewHolder();
                            @SuppressWarnings("static-access")
                            LayoutInflater li = (LayoutInflater)mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);  
    
    
                            v = li.inflate(R.layout.category_icon, null);
                            vh.tv= (TextView)v.findViewById(R.id.icon_text);
    
                            vh.iv = (ImageView)v.findViewById(R.id.icon_image);
    
                            v.setTag(vh);
                        }
                        else
                        {
                            vh = (viewHolder)convertView.getTag();
                            v = convertView;
                        }
                            try {
                                URL aURL = new URL(CategorylogoActivity.logoarray[position]);
                                URLConnection conn = aURL.openConnection();
                                conn.connect();
                                InputStream is = conn.getInputStream();
                                // Buffered is always good for a performance plus. 
                                BufferedInputStream bis = new BufferedInputStream(is);
                                // Decode url-data to a bitmap. 
                                bm = BitmapFactory.decodeStream(bis);
    
                                bis.close();
                                is.close();
                            } catch (MalformedURLException e) {
    
                                e.printStackTrace();
                            } catch (IOException e) {
    
                                e.printStackTrace();
                            }
                         vh.iv.setImageBitmap(bm);
                        vh.tv.setText(CategorylogoActivity.namearray[0]);
    
                        return v;
    

    you have to use viewHolder kind of object, when the convertView is not null, your iv imageView is null . so you are using setImageBitmap() on null object. try my code.

    HTH.

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

Sidebar

Related Questions

I try to do it in the following way: public String getValue(String service, String
I try the following code, but it doesn't work. [helloToolbar setBackgroundColor:[UIColor clearColor]];
I was playing with $.getJSON in the following way to receive an alert but
I am getting the following error when I try to instantiate an instance of
I'm getting the above error when I try to run the following code: int
The following servlet filter is getting called, but not able to give the correct
Try the following code public enum Color { Blue=1, Red=2, Green=3 } public List<Color>
Try the following code: s = '#value#' puts s.gsub('#value#', Regexp.escape('*')) # => '\*' puts
When I try the following lookup in my code: Context initCtx = new InitialContext();
I get the following error message when I try the following: Dim XL As

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.