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

  • Home
  • SEARCH
  • 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 8487657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:18:35+00:00 2026-06-10T21:18:35+00:00

I’m struggling with compiling and running an example from the Android developer web site:

  • 0

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>

  • 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-10T21:18:37+00:00Added an answer on June 10, 2026 at 9:18 pm

    Looks like you have imported wrong LoadManager i.e android.support.v4.app.LoaderManager; try importing this : android.app.LoaderManager it may work.

    Documentation : http://developer.android.com/reference/android/app/LoaderManager.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m struggling to understand this concept: I have a fixed size definition: (from http://msdn.microsoft.com/pt-br/library/aa931918.aspx
I am using Xcode and, after some struggling, it is compiling my dynamic libraries
I'm struggling with a scenario where I have a managed interface exposed through COM
I've been struggling with Compiling transformation: An assembly with the same identity 'xxxx' has
I am struggling with returning a complex type from my services layer. It doesnt
We're struggling to come up with a command name for our all purpose developer
im struggling to connect to my mysql service running on my local windows 7
Struggling in vain to extract the value of the Status descendant from an XML
Struggling to load json from file (myData.json) on URL into an object so I
Struggling to get any list function to work. I've been fine with _show and

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.