Question

I am working with an application by using Service class to run the app at back ground on every time.The service class will run at back ground.In my service class i have used a Time for run my at back ground on every time.In this case i am not getting an error in my emulator but if i run my app real device i am getting FATAL EXCEPTION Timer-0 error.

I have implemented my application as follows:

 public class RepeatService extends Service
 {
 ArrayList<ShoutMessage> resultMessage;
 private Timer timer = new Timer();
 private static final long UPDATE_INTERVAL = 30000;
 @Override
public IBinder onBind(Intent arg0) {
    return null;
}

@Override
public void onCreate() {

    pollForUpdates();
    super.onCreate();
}  

 private void pollForUpdates() {
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {


            resultShoutMessage = new ParseXml().convertMessages(new Model().getMessages(getID));

            for(int i=0;i<resultMessage.size();i++)
            {
                String userID = resultMessage.get(i).getUserID();
                String userName = resultMessage.get(i).getUserFirstName();
                String messageID= resultMessage.get(i).getMessageID();
                String userMessage=resultMessage.get(i).getMessageText();


            }

                intent.setAction("com.sample.presentationLayer");
                sendBroadcast(intent); // finally broadcast
        }
    }, 0, UPDATE_INTERVAL);

}


 @Override
public void onDestroy() {
    timer.cancel();

    super.onDestroy();
}

}

When i run the above implementation i am getting an error as follows:

 01-01 01:18:34.414: ERROR/AndroidRuntime(2049): FATAL EXCEPTION: Timer-0
 01-01 01:18:34.414: ERROR/AndroidRuntime(2049): java.lang.NullPointerException
 01-01 01:18:34.414: ERROR/AndroidRuntime(2049):     at com.fitzgerald.presentationLayer.RepeatService$1.run(RepeatService.java:63)
01-01 01:18:34.414: ERROR/AndroidRuntime(2049):     at java.util.Timer$TimerImpl.run(Timer.java:289)

How can i resolve the above issue in my application?

please any body help me

Était-ce utile?

La solution

Instead its a NullPointerException in your RepeatService.java at line number 63 inside run(). Just resolve it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top