HandleServiceArgs空指针异常〜Android游戏

HandleServiceArgs空指针异常〜Android游戏

本文介绍了HandleServiceArgs空指针异常〜Android游戏服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个程序,如果用户更改root访问状态检测。用户定义的任何时间段。在这个时间段,它控制rootaccess状态。当我启动该服务,它提供了一个错误。其实在此之前的工作,但现在它不是。我找不到任何空变量。
我打开应用程序管理器上的设备,并期待运行的服务。它说,这项服务'重新开始'。

RootAccess服务;

 公共类RootAccessService延伸服务{@覆盖
公众的IBinder onBind(意向意图){
    返回null;
}@覆盖
公共无效调用onStart(意向意图,诠释startId){    束B = intent.getExtras();
    如果(B!= NULL){        上下文= getApplicationContext();
        助手=新SQLiteHelper(背景);
        定时器=新定时器();
        处理器=新的处理程序();
        inventoryId = 1;
        periodSelection = b.getString(期间);        份= periodSelection.split();
        分=的Long.parseLong(部件[0]);
        时间=分钟* 60 * 1000;
        KILLME = FALSE;
        handler.postDelayed(检查,时间);
    }}
私人最终可运行检查=新的Runnable(){    @覆盖
    公共无效的run(){
        // TODO自动生成方法存根
        如果(KILLME)
            返回;
        开始();
        handler.postDelayed(检查,时间);
    }
};@覆盖
公共无效的onDestroy(){
    停止();
    super.onDestroy();}公共无效启动(){
    //做smtg
}公共无效停止(){
    handler.removeCallbacksAndMessages(检查);
    KILLME = TRUE;
    helper.close();
}

}

  14 12-18:02:24.783:E / AndroidRuntime(18004):致命异常:主要
12-18 14:02:24.783:E / AndroidRuntime(18004):了java.lang.RuntimeException:无法启动服务com.example.cryptodlp.RootAccessService@41de6fd0与空:显示java.lang.NullPointerException
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2553)12-18 14:02:24.783:E / AndroidRuntime(18004):在android.app.ActivityThread.access $ 2000(ActivityThread.java:134)
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1321)
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.os.Handler.dispatchMessage(Handler.java:99)
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.os.Looper.loop(Looper.java:137)
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.app.ActivityThread.main(ActivityThread.java:4867)
12-18 14:02:24.783:E / AndroidRuntime(18004):在java.lang.reflect.Method.invokeNative(本机方法)
12-18 14:02:24.783:E / AndroidRuntime(18004):在java.lang.reflect.Method.invoke(Method.java:511)
12-18 14:02:24.783:E / AndroidRuntime(18004):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1007)
12-18 14:02:24.783:E / AndroidRuntime(18004):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
12-18 14:02:24.783:E / AndroidRuntime(18004):在dalvik.system.NativeStart.main(本机方法)
12-18 14:02:24.783:E / AndroidRuntime(18004):致:显示java.lang.NullPointerException
12-18 14:02:24.783:E / AndroidRuntime(18004):在com.example.cryptodlp.RootAccessService.onStart(RootAccessService.java:49)
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.app.Service.onStartCommand(Service.java:450)
12-18 14:02:24.783:E / AndroidRuntime(18004):在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2536)
12-18 14:02:24.783:E / AndroidRuntime(18004):10 ...更多


解决方案

我搜索这个问题,我用AlarmManager并开始与AlarmManager服务。

 日历CAL = Calendar.getInstance();意向意图=新意图(mContext,RootAccessService.class);
的PendingIntent pintent = PendingIntent.getService(mContext,0,意向,0);AlarmManager报警=(AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis()的Integer.parseInt(部件[0])* 60 * 1000,pintent);

This program detects if user change the root access status. User define any time period. In this time period, it controls the rootaccess status. When I start the service, it gives an error. Actually it was working before but now its not. I couldn't find any null variable.I open Application Manager on device and look to running services. It says 'starting again' for this service.

RootAccess Service;

public class RootAccessService extends Service{

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onStart(Intent intent,int startId) {

    Bundle b= intent.getExtras();
    if(b != null){

        context = getApplicationContext();
        helper = new SQLiteHelper(context);
        timer = new Timer();
        handler = new Handler();
        inventoryId = 1;
        periodSelection = b.getString("period");

        parts = periodSelection.split(" ");
        min = Long.parseLong(parts[0]);
        time = min * 60 * 1000;
        killMe = false;
        handler.postDelayed(check, time);
    }

}


private final Runnable check = new Runnable() {

    @Override
    public void run() {
        // TODO Auto-generated method stub
        if(killMe)
            return;
        Start();
        handler.postDelayed(check, time);
    }
};

@Override
public void onDestroy(){
    Stop();
    super.onDestroy();

}

public void Start(){
    //do smtg
}

public void Stop(){
    handler.removeCallbacksAndMessages(check);
    killMe = true;
    helper.close();
}

}

12-18 14:02:24.783: E/AndroidRuntime(18004): FATAL EXCEPTION: main
12-18 14:02:24.783: E/AndroidRuntime(18004): java.lang.RuntimeException: Unable to start service com.example.cryptodlp.RootAccessService@41de6fd0 with null: java.lang.NullPointerException
12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2553)

12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.app.ActivityThread.access$2000(ActivityThread.java:134)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at  android.os.Handler.dispatchMessage(Handler.java:99)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.os.Looper.loop(Looper.java:137)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.app.ActivityThread.main(ActivityThread.java:4867)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at java.lang.reflect.Method.invokeNative(Native Method)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at java.lang.reflect.Method.invoke(Method.java:511)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at dalvik.system.NativeStart.main(Native Method)
12-18 14:02:24.783: E/AndroidRuntime(18004): Caused by: java.lang.NullPointerException
12-18 14:02:24.783: E/AndroidRuntime(18004):    at com.example.cryptodlp.RootAccessService.onStart(RootAccessService.java:49)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.app.Service.onStartCommand(Service.java:450)
12-18 14:02:24.783: E/AndroidRuntime(18004):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2536)
12-18 14:02:24.783: E/AndroidRuntime(18004):    ... 10 more
解决方案

I searched this problem and I used AlarmManager and start the service with AlarmManager.

Calendar cal = Calendar.getInstance();

Intent intent = new Intent(mContext, RootAccessService.class);
PendingIntent pintent = PendingIntent.getService(mContext, 0, intent, 0);

AlarmManager alarm = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), Integer.parseInt(parts[0])*60*1000, pintent);

这篇关于HandleServiceArgs空指针异常〜Android游戏服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:24