I’m struggling with compiling and running an example from the Android developer web site: http://developer.android.com/guide/topics/ui/layout/listview.html
Here is my typed in version:
package com.chex.control;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ListAdapter;
import android.support.v4.app.LoaderManager;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v4.content.Loader;
import android.support.v4.content.CursorLoader;
public class ListViewExample extends ListActivity implements
LoaderManager.LoaderCallbacks<Cursor> {
Cursor cursor;
// database columns that we will retreive
final String[] PROJECTION = new String[] { ContactsContract.Data._ID,
ContactsContract.Data.DISPLAY_NAME };
final String SELECTION = "((" + ContactsContract.Data.DISPLAY_NAME
+ " NOTNULL AND (" + ContactsContract.Data.DISPLAY_NAME
+ " != ''))";
SimpleCursorAdapter adapter=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] fromColumns = { ContactsContract.Data.DISPLAY_NAME };
int[] toViews = { android.R.id.text1 };
ListAdapter adapter = new SimpleCursorAdapter(this, // context
android.R.layout.simple_list_item_1, cursor, // cursor to bind
// to
fromColumns, // array of cursor
// columns to
// bind to
toViews, 0); // parallel
// array
// of
// which
// template
// objects
// to
// bind
// to
// cursor
// columns
setListAdapter(adapter);
// ******* THE FOLLOWING LINE WON'T COMPILE **************
getLoaderManager().initLoader(0, null, this);
}
@Override
public void setListAdapter(ListAdapter adapter) {
// TODO Auto-generated method stub
super.setListAdapter(adapter);
}
/**
* create and return a CursorLoader that will take care of creating a Curso
* for the data being displayed.
*/
@Override
public Loader onCreateLoader(int arg0, Bundle arg1) {
CursorLoader loader = new CursorLoader(this,
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
null);
return loader;
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
// TODO Auto-generated method stub
}
}
Eclipse gives a compile error:
The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks<D>) in the type LoaderManager is not applicable for the arguments (int, null, ListViewExample).
Obviously, the cast wants not so is the example wrong? I have the same problem if I simply cut and paste from the Android developer site.
When I change the <Cursor> to <D> in my code, the cast fails during execution. I don’t know why – it looks to me like the class fulfills the LoaderCallbacks contract when it implements <D>
Looks like you have imported wrong LoadManager i.e
android.support.v4.app.LoaderManager;try importing this :android.app.LoaderManagerit may work.Documentation : http://developer.android.com/reference/android/app/LoaderManager.html