Image in database to listview android

I am trying to show in a listview in android some images that I have in a database and this part

    public View getView (int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater ();
        View listViewItem = inflater.inflate (R.layout.layout, null, true);
        TextView androids = (TextView) listViewItem.findViewById (;
        // TextView textView = (TextView) listViewItem.findViewById (;
        // textView.setText (urls [position]);
        androidos.setText (androidosnames [position]);
        ImageView image = (ImageView) listViewItem.findViewById (;
        image.setImageBitmap (Bitmap.createScaledBitmap (bitmaps [position], 100, 50, false));
        return listViewItem;

It gives me the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'int ()' on a null object reference

1 answer

  • answered 2019-03-14 10:05 Jose Manuel

    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 Customadapter extends ArrayAdapter<String> {
        private String[] androidosnames;
        //private String[] urls;
        private Bitmap[] bitmaps;
        private Activity context;
        public Customadapter(Activity context,    String[] androidosnames,  Bitmap[] bitmaps  ) {
            super(context, R.layout.activity_delivery, androidosnames);
            this.context = context;
            // this.urls = urls;
            this.bitmaps = bitmaps;
            this.androidosnames = androidosnames;
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = context.getLayoutInflater();
            View listViewItem = inflater.inflate(R.layout.layout, null, true);
            TextView  androidos = (TextView) listViewItem.findViewById(;
            // TextView textView = (TextView) listViewItem.findViewById(;
            //  textView.setText(urls[position] );
            androidos.setText(androidosnames[position] );
            ImageView image = (ImageView) listViewItem.findViewById(;
            image.setImageBitmap(Bitmap.createScaledBitmap(bitmaps[position], 100, 50, false));
            return  listViewItem;