장치에 설치된 다른 응용 프로그램에서 서비스를 시작하려고합니다. java.lang.NullPointerException IntentService
public void notConnected(){
Log.i(TAG,"no connection... reconnecting.");
Intent reset = new Intent("com.famoco.intent.action.TOGGLE_DATA");
Log.i(TAG,"calling " + reset.getAction());
if(reset.getAction().equals("com.famoco.intent.action.TOGGLE_DATA"))
{
startService(reset);
}
else
{
Log.i(TAG,"couldn't start service");
}
}
startService
를 사용할 때 NullPointerException이를 얻을이E/AndroidRuntime: FATAL EXCEPTION: IntentService[MyAppCommService]
Process: com.myapppackage.MyApp, PID: 8583
java.lang.NullPointerException
at android.content.ContextWrapper.startService(ContextWrapper.java:494)
at com.myapppackage.MyApplocation.activity.MyAppActivity.notConnected(MyAppActivity.java:591)
at com.myapppackage.MyApplocation.api.MyAppApi.submitClock(MyAppApi.java:228)
at com.myapppackage.MyApplocation.service.MyAppCommService.submitTags(MyAppCommService.java:52)
at com.myapppackage.MyApplocation.service.MyAppCommService.onHandleIntent(MyAppCommService.java:98)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:61)
내 컨텍스트가 null 반환 내가에서 onCreate에서 컨텍스트를 얻고 myContext.startservice를 호출하여 고정 밝혀 오류 로그입니다.
context.startService()
당신이 더 많은 코드를 공유 할 수 호출하여 고정? – Skullper어떤 코드가 필요합니까? – Rodin10
잘 모르겠습니다. 다음과 같이 서비스를 지정해야 할 수도 있습니다. 'startService (new Intent (this, MyService.class)); – Skullper