I would create some listview from my api json response, but I stuck with this LinkedTreeMap error in my code. Could anyone help me to solve this?

public class KategoriListAdapter extends BaseAdapter {

    Context context;
    ArrayList<Barang> barang;

    public KategoriListAdapter(Context context, ArrayList<Barang> barang) {
        this.context = context;
        this.barang = barang;

    public int getCount() {
        return barang.size();

    public Barang getItem(int i) {
        return this.barang.get(i);

    public long getItemId(int i) {
        return i;

    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.custom_list_view_kategori, viewGroup, false);

        TextView tvNama = (TextView) view.findViewById(R.id.tv_nama);
        TextView tvHarga = (TextView) view.findViewById(R.id.tv_harga);
        TextView tvUsername = (TextView) view.findViewById(R.id.tv_username);

        Object getrow = this.barang.get(i);
        LinkedTreeMap<Object, Object> rowmap = (LinkedTreeMap) getrow;
        String nama = rowmap.get("nama").toString();
        String harga = rowmap.get("harga").toString();
        String username = rowmap.get("username").toString();


        return view;


public class Barang {

    private Integer id;
    private String username;
    private String nama;
    private String harga;
    private String gambar;

    public Integer getId() {
        return id;

    public void setId(Integer id) {
        this.id = id;

    public String getUsername() {
        return username;

    public void setUsername(String username) {
        this.username = username;

    public String getNama() {
        return nama;

    public void setNama(String nama) {
        this.nama = nama;

    public String getHarga() {
        return harga;

    public void setHarga(String harga) {
        this.harga = harga;

    public String getGambar() {
        return gambar;

    public void setGambar(String gambar) {
        this.gambar = gambar;


The log result while I run the activity is

java.lang.ClassCastException: com.example.barangkoz.model.Barang cannot be 
cast to com.google.gson.internal.LinkedTreeMap
    at     com.example.barangkoz.activities.KategoriListAdapter.getView(KategoriListAdapter.java:57)`

Related posts

Recent Viewed