Issues with 9.18 - call to super


#1

Hello,

either it is a bad case of Monday or I just don’t see it… The compiler doesn’t see it either :slight_smile:

public CrimeAdapter(ArrayAdapter<Crime> crimes){
    super(getActivity(), 0, crimes);
}

The compiler says:

I happen to agree with the compiler after checking the documentation and inheritance traces. And yet … it’s in the book :slight_smile: And others didn’t flag it (I did a bit of research here before posting). :astonished:

Little help?

Thanks,
Radu


#2

It works for me. I have just finished this chapter a few minutes ago.
Could you post your entire CrimeListFragment.java file?


#3

Sure, here it is:

package com.somepackage.app;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;
public class CrimeListFragment extends ListFragment
{
    private static ArrayList<Crime> mCrimes;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getActivity().setTitle(R.string.crimes_title);
        mCrimes = CrimeLab.get(getActivity()).getCrimes();
        ArrayAdapter<Crime> adapter = new ArrayAdapter<Crime>(getActivity(), android.R.layout.simple_list_item_1, mCrimes);
        setListAdapter(adapter);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {
        Crime c = (Crime) (getListAdapter()).getItem(position);
    }

    private class CrimeAdapter extends ArrayAdapter<Crime>
    {
        public CrimeAdapter(ArrayAdapter<Crime> crimes)
        {
            super(getActivity(), 0, crimes);
        }
    } 
}

The problem both the compiler and I see is that the call to super goes to the constructor of the ArrayAdapter class extended by CrimeAdapter, except that there no constructor that takes the last parameter an ArrayAdapter as the book example shows it should, nor something else compatible.

For convenience, here’s a copy/paste of all the constructors from ArrayAdapter from API18 documentation:

ArrayAdapter(Context context, int resource)
ArrayAdapter(Context context, int resource, int textViewResourceId)
ArrayAdapter(Context context, int resource, T[] objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int resource, List<T> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)

The BaseAdapter abstract parent class doesn’t help either (plus being abstract, whatever would have helped there would have been visible in ArrayAdapter anyway).

Let me know if anything else from my workspace can be of use and I can post it here.

Cheers!


#4

Duh … it was a bad case of Monday … I found my own mistake.

Correct:

public CrimeAdapter(Array[color=#BF0000]List[/color] crimes)

My code:

public CrimeAdapter(Array[color=#BF0000]Adapter[/color] crimes)

I used auto-completion too fast and I guess Adapter came before List as an option.

Doing my push-ups now :slight_smile:

Regards!