Loader Manager Sample

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Loader Manager Sample

Postby venkatraman7 » Thu Jan 17, 2013 12:29 pm

Hi all,
I am trying to load contact information in android using LoadManager below is the code
Code: Select all
package org.test.loadersample;

import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.widget.ListView;

public class LoaderSample extends FragmentActivity implements LoaderManager.LoaderCallbacks <Cursor> {
   protected SimpleCursorAdapter mAdapter;

    public void onCreate(Bundle savedInstanceState) {
       [b] mAdapter=new SimpleCursorAdapter(this, R.layout.list_item,
              null, new String[] {"Contact Name"},
              new int[] {R.id.contact_name}, 0);[/b]
        ListView lv=(ListView) findViewById(R.id.list);
       [b] lv.setAdapter(mAdapter);[/b]

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_loader_sample, menu);
        return true;

   public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
      // TODO Auto-generated method stub
      Uri contentUri;
      return new CursorLoader(this, contentUri, null, null, null, null);

   public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
      // TODO Auto-generated method stub

   public void onLoaderReset(Loader<Cursor> arg0) {
      // TODO Auto-generated method stub

I am getting NPE (Null Pointer Exception) on line 29. I can't able to figure out the reason...
Please guide me to run this sample application
Posts: 41
Joined: Tue Nov 16, 2010 6:47 am
Location: Puducherry


Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests