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;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_loader_sample);
       
       [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]
       
    }

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

   @Override
   public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
      // TODO Auto-generated method stub
      Uri contentUri;
      contentUri=ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
      return new CursorLoader(this, contentUri, null, null, null, null);
   }

   @Override
   public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
      // TODO Auto-generated method stub
      mAdapter.swapCursor(arg1);
   }

   @Override
   public void onLoaderReset(Loader<Cursor> arg0) {
      // TODO Auto-generated method stub
      mAdapter.swapCursor(null);
   }
}




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
venkatraman7
Developer
Developer
 
Posts: 41
Joined: Tue Nov 16, 2010 6:47 am
Location: Puducherry

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests