Cursor value null..
hi i am developing an app which get outgoing sms content through content resolver but it is giving some problem plz help me.

package com.company.cellSafetyZone.model;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class OutGoingSmsService extends Service
{	Context context;
	SmsObserver smsObserver;
	Cursor cursor;
	Handler handler=new  Handler();
	private String TAG="SMS SERVICE";
	boolean change;
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	public OutGoingSmsService() 
	{
		Log.d(TAG,"blank constructor");
		// TODO Auto-generated constructor stub
	}
	public OutGoingSmsService(Context context)
	{
		Log.d(TAG,"context constructor");
		this.context=context;
		
	}
	@Override
	public void onCreate()
	{	Log.d(TAG,"in on Create() of sms service");
		super.onCreate();
		smsObserver=new SmsObserver(handler);
		 Log.d(TAG,"calling service");
		startService();
	}
	private void startService()
	{ Log.d(TAG,"registering resolver");
	cursor=this.getContentResolver().query(Uri.parse("content://sms/sent"), null,null,null,null);
		Log.d(TAG,"registering observer");
       cursor.registerContentObserver(smsObserver);
        Log.d(TAG,"registerd");
	}
	void setChangeValue(boolean selfChange)
	{System.out.println("in setChange");
		change=selfChange;
		if(change==false)
        {	  try
{   	cursor=context.getContentResolver().query(Uri.parse("content://sms/sent"), null,null,null,null);
        	cursor.moveToFirst(); 
    		}catch (Exception e)
			{	System.out.println("in catch."+e.getMessage());
				e.printStackTrace();
			}
    		String protocol=cursor.getString(cursor.getColumnIndex("protocol"));
    		Log.d(TAG,"protocol value."+protocol);
    		if(protocol==null)
    			onSmsSend();
    		}}
	private void onSmsSend()
	{ cursor.moveToFirst();
    	for (int i = 0; i <cursor.getColumnCount(); i++) 
    	{String column=cursor.getColumnName(i);
    		String msg=cursor.getString(i);	}}}


it is calling observer and get back in this service again in onSmsSend() method.but now giving an exception.
 java.lang.NullPointerException
atcom.company.cellSafetyZone.model.OutGoingSmsService.setChangeValue(OutGoingSmsService.java:104)
at com.company.cellSafetyZone.model.SmsObserver.onChange(SmsObserver.java:42)
at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)
 why cursor is null..
there is a small thing which i am unable to catch so help me out plz


Cursor value null..
===

hi i am developing an app which get outgoing sms content through content resolver but it is giving some problem plz help me.

package com.company.cellSafetyZone.model;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class OutGoingSmsService extends Service
{	Context context;
	SmsObserver smsObserver;
	Cursor cursor;
	Handler handler=new  Handler();
	private String TAG="SMS SERVICE";
	boolean change;
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	public OutGoingSmsService() 
	{
		Log.d(TAG,"blank constructor");
		// TODO Auto-generated constructor stub
	}
	public OutGoingSmsService(Context context)
	{
		Log.d(TAG,"context constructor");
		this.context=context;
		
	}
	@Override
	public void onCreate()
	{	Log.d(TAG,"in on Create() of sms service");
		super.onCreate();
		smsObserver=new SmsObserver(handler);
		 Log.d(TAG,"calling service");
		startService();
	}
	private void startService()
	{ Log.d(TAG,"registering resolver");
	cursor=this.getContentResolver().query(Uri.parse("content://sms/sent"), null,null,null,null);
		Log.d(TAG,"registering observer");
       cursor.registerContentObserver(smsObserver);
        Log.d(TAG,"registerd");
	}
	void setChangeValue(boolean selfChange)
	{System.out.println("in setChange");
		change=selfChange;
		if(change==false)
        {	  try
{   	cursor=context.getContentResolver().query(Uri.parse("content://sms/sent"), null,null,null,null);
        	cursor.moveToFirst(); 
    		}catch (Exception e)
			{	System.out.println("in catch."+e.getMessage());
				e.printStackTrace();
			}
    		String protocol=cursor.getString(cursor.getColumnIndex("protocol"));
    		Log.d(TAG,"protocol value."+protocol);
    		if(protocol==null)
    			onSmsSend();
    		}}
	private void onSmsSend()
	{ cursor.moveToFirst();
    	for (int i = 0; i <cursor.getColumnCount(); i++) 
    	{String column=cursor.getColumnName(i);
    		String msg=cursor.getString(i);	}}}


it is calling observer and get back in this service again in onSmsSend() method.but now giving an exception.
 java.lang.NullPointerException
atcom.company.cellSafetyZone.model.OutGoingSmsService.setChangeValue(OutGoingSmsService.java:104)
at com.company.cellSafetyZone.model.SmsObserver.onChange(SmsObserver.java:42)
at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)
 why cursor is null..
there is a small thing which i am unable to catch so help me out plz

