0

I'm attempting to bundle extras between a service and another class I've built but I'm having trouble due to a force close error stating "java.lang.NullPointerException at com.test.generic.clientprovisioninghandler.DataCountService.onStartCommand(DataCountService.java:46)"

Which is the line Bundle extras = getIntent().getExtras();

Any suggestions as to how to correct this are greatly appreciated!

SOURCE:

public class DataCountService extends Service {
    String text = "USR;1";
    String ERROR = Constants.PREFS_NAME;
    private Timer timer = new Timer();
    private long period;
    private long delay_interval;

    private Intent getIntent() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(Constants.TAG, "Logging Service Started");

        if (intent == null) {
            // Exit gracefully is service not started by intent
            Log.d(Constants.TAG, "Error: Null Intent");
        } else {
            Bundle extras = getIntent().getExtras();

            if (extras != null) {
                text = extras.getString(Constants.DM_SMS_CONTENT);
                // check for Enable or Disable Value - if set to enable
                // check for Enable or Disable Value - if set to enable
                if (extras.getString(Constants.DM_SMS_CONTENT).contains(
                        "//USR;1")) {
4

2 回答 2

3

在你DataCountService 的课上,你忘了实现下面的方法:

private Intent getIntent() {
        // TODO Auto-generated method stub
        return null;
    }

总是返回 null。

在那里实现你的逻辑,并返回结果。

于 2013-06-24T18:57:04.550 回答
0

我不明白你的自定义getIntent()方法。我猜你想使用作为参数传递的意图:

Bundle extras = intent.getExtras();
于 2013-06-24T19:01:56.993 回答