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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:42:47+00:00 2026-06-08T20:42:47+00:00

New to android here, (and programming in general) I’m following this example trying to

  • 0

New to android here, (and programming in general)

I’m following this example trying to create a lazy image loading adapter: http://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/
I’m using “Album” instead of Student, but the rest is pretty much the same.

When I call the following from my adapter:

Album getItem(int position) {
    return items.get(position);
}

I get “Type mismatch: cannot convert from Object to Album”. I tried copying the code from the example verbatim, and I got the same error..

Could somebody please explain what I am doing wrong, and how to fix it? Thank you.

Here is the code:

Album class:

package another.music.player;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;

public class Album {

    private String album;

    private String imageUri;

    private Bitmap image;

    private AlbumAdapter albumAdapter;

    public Album(String album, String imageUri) {

        this.album = album;
        this.imageUri = imageUri;

        // Default image
        this.album = null;
    }

    public String getAlbum() {
        return album;
    }

    public void setAlbum(String album) {
        this.album = album;
    }

    public String getImageUri() {
        return imageUri;
    }

    public void setImageUri(String imageUri) {
        this.imageUri = imageUri;
    }

    public Bitmap getImage() {
        return image;
    }

    public AlbumAdapter getAdapter() {
        return albumAdapter;
    }

    public void setAdapter(AlbumAdapter albumAdapter) {
        this.albumAdapter = albumAdapter;
    }

    public void loadImage(AlbumAdapter albumAdapter) {
        // Hold a reference to the adapter
        this.albumAdapter = albumAdapter;
        if (imageUri != null && !imageUri.equals("")) {
            new ImageLoadTask().execute(imageUri);
        }
    }

    // Async task
    private class ImageLoadTask extends AsyncTask<String, String, Bitmap> {
        @Override
        protected void onPreExecute() {
            Log.i("ImageLoadTask", "Loading Image..");
        }

        // Param[0] is Image URI
        protected Bitmap doInBackground(String... param) {
            Log.i("ImageLoadTask", "Attempting to load image Uri: " + param[0]);
            try {
                Bitmap bitmap = ImageService.getBitmapFromURI(param[0]);
                return bitmap;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

        protected void onProgressUpdate(String... progress) {
            // No Op
        }

        protected void onPostExecute(Bitmap ret) {
            if (ret != null) {
                Log.i("ImageLoadTask", "Successfully loaded" + album + " image");
                image = ret;
                if (albumAdapter != null) {
                    // When image is loaded, notify the adapter
                    albumAdapter.notifyDataSetChanged();
                }
            } else {
                Log.e("ImageLoadTask", "Failed to load " + album + " image");
            }
        }
    }
}

AlbumAdapter Class:

package another.music.player;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlbumAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private List items = new ArrayList();

    public AlbumAdapter(Context context, List items) {
        mInflater = LayoutInflater.from(context);
        this.items = items;
    }

    public int getCount() {
        return items.size();
    }

    public Album getItem(int position) {
        return items.get(position);
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        Album album = items.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.row_layout, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.image = (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(album.getName());
        if (s.getImage() != null) {
            holder.pic.setImageBitmap(s.getImage());
        } else {
                // MY DEFAULT IMAGE
            holder.pic.setImageResource(R.drawable.generic_profile_man);
        }
        return convertView;
    }

    static class ViewHolder {
        TextView name;

        ImageView pic;
    }

}
  • 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-08T20:42:49+00:00Added an answer on June 8, 2026 at 8:42 pm

    You have a generic List, which will contain Object instances. That means any instance of the Object class or a class that extends Object (essentially all of them). When you attempt to get an item out of that list, the compiler knows that it’s an Object, but your method signature is saying you’re returning an Album; the compiler doesn’t know that the element you’re retrieving from the list definitely is an Album, so it can’t compile the code.

    You can solve this is one of two ways. You can declare your List to only contain instances of the Album class:

    List<Album> items = new ArrayList<Album>();
    

    Or you can cast the object you’re retrieving from the list, to tell the compiler that you are definite that it’s an Album even if it isn’t:

    Album getItem(int position) {
        return (Album)items.get(position);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first post here. I'm new in Android Programming. I want to
I'm fairly new to Android programming. I'm trying to create an animation of a
I am new to xml and android programming.Here is my xml code... I don't
Extreme Android developer newbie here...well, new to Android development, not development in general. I
I am new to Eclipse and Android programming in general but I have been
I'm very new to Android programming, so this is probably something pretty basic. I
Hi I'm new to Android Programming and I'm trying to make a simple program
I am new to Android programming, but not to programming in general or Java.
I am new to android,actually this is my second program.I am programming from last
Am very new to Android programming, so sorry if this is a simple problem.

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.