Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Segue o stacktrace:

02-02 11:04:20.347    7485-7485/br.com.trackmob.electrolux E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: br.com.trackmob.electrolux, PID: 7485
    java.lang.RuntimeException: Unable to create service br.com.trackmob.electrolux.helpers.core.CoreService: java.lang.NullPointerException: Attempt to write to field 'br.com.trackmob.electrolux.helpers.battery.BatteryHelper br.com.trackmob.electrolux.helpers.core.CoreService.batteryHelper' on a null object reference
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2773)
            at android.app.ActivityThread.access$1800(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5314)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
     Caused by: java.lang.NullPointerException: Attempt to write to field 'br.com.trackmob.electrolux.helpers.battery.BatteryHelper br.com.trackmob.electrolux.helpers.core.CoreService.batteryHelper' on a null object reference
            at br.com.trackmob.electrolux.helpers.core.CoreService.initializeService(CoreService.java:155)
            at br.com.trackmob.electrolux.helpers.core.CoreService.onCreate(CoreService.java:136)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2764)
            at android.app.ActivityThread.access$1800(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5314)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

Bruno Vercelino da Hora
--
"Mas Deus prova o seu próprio amor para conosco pelo fato de ter Cristo morrido por nós, sendo nós ainda pecadores." - Romanos 5:8
"Mas em nada tenho a minha vida como preciosa para mim, contando que complete a minha carreira e o ministério que recebi do Senhor Jesus, para dar testemunho do evangelho da graça de Deus." - Atos 20:24

2015-02-02 11:28 GMT-02:00 luciofm <luciofm@gmail.com>:
Sempre que for pedir ajuda com um NullPointerException, ou com qualquer outra exception, poste o stacktrace...

On Mon Feb 02 2015 at 11:09:43 AM Geovani **Leia a documentação oficial** de Souza <geovanisouza92@gmail.com> wrote:
Fora isso, usar alternativas como Dagger ajuda a estirpar parte da complexidade com injeção de dependências.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/androidbrasil-dev/jOq2c3-Cb3M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

Re: [androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Sempre que for pedir ajuda com um NullPointerException, ou com qualquer outra exception, poste o stacktrace...

On Mon Feb 02 2015 at 11:09:43 AM Geovani **Leia a documentação oficial** de Souza <geovanisouza92@gmail.com> wrote:
Fora isso, usar alternativas como Dagger ajuda a estirpar parte da complexidade com injeção de dependências.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

Re: [androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Fora isso, usar alternativas como Dagger ajuda a estirpar parte da complexidade com injeção de dependências.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

Re: [androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Adoro Android e essas bruxarias! kkkk

Se quiser postar, recomendo postar no Gist e deixar o link aqui.

Sobre o problema, vc tem certeza que todos os seus "helpers" e esse método "getBaseContext()" são safe? Em nenhum momento eles deixam de ser static ou são sobrescritos?

Já passei por um caso maluco desses algumas vezes e em geral, o erro surge de outro lugar que não tem nada a ver com a sequência do código...

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

Re: [androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Oi Geovani, posso colocar a classe inteira, mas ela é gigantesca (muito mal feita, diga-se de passagem).

Mas como disse, quando executo com o debugger linha a linha o NullPointer não ocorre.
É isso que me deixa mais confuso nesse problema.


Bruno Vercelino da Hora
--
"Mas Deus prova o seu próprio amor para conosco pelo fato de ter Cristo morrido por nós, sendo nós ainda pecadores." - Romanos 5:8
"Mas em nada tenho a minha vida como preciosa para mim, contando que complete a minha carreira e o ministério que recebi do Senhor Jesus, para dar testemunho do evangelho da graça de Deus." - Atos 20:24

Em 2 de fevereiro de 2015 10:52, Geovani **Leia a documentação oficial** de Souza <geovanisouza92@gmail.com> escreveu:
Bom Bruno, é muita coisa que ainda não diz muita coisa, já que seu onCreate chama diversos outros métodos que não estão listado aí.

De qualquer forma, vc já tentou colocar um breakpoint na dita linha e ir executando passo-a-passo com o debuger (inclusive entrando nos métodos) e visualizando os valores de cada variável no painel Variables? (estou supondo que vc usa Android Studio)

--
You received this message because you are subscribed to a topic in the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/androidbrasil-dev/jOq2c3-Cb3M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

[androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Bom Bruno, é muita coisa que ainda não diz muita coisa, já que seu onCreate chama diversos outros métodos que não estão listado aí.

De qualquer forma, vc já tentou colocar um breakpoint na dita linha e ir executando passo-a-passo com o debuger (inclusive entrando nos métodos) e visualizando os valores de cada variável no painel Variables? (estou supondo que vc usa Android Studio)

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

[androidbrasil-dev] Re: NullPointer no método onCreate de um Service

Obrigado pela atenção.

Sim eu chamei o super.onCreate().
Estou mandando o método onCreate, não vou mandar tudo pq é muita coisa.
Mas o trecho é basicamente inicializações de campos.

O erro ocorre no:
 batteryHelper = BatteryHelper.getInstance(getBaseContext());

E quando eu rodo o Debug, a variável é instanciada corretamente.

[]s 

 @Override
    public void onCreate() {
        super.onCreate();
        
        // initiate network helper
        if (networkHelper == null)
            networkHelper = new NetworkHelper(getBaseContext(), this);
        // initiate database helper
        if (dbHelper == null)
            dbHelper = new OSDatabaseHelper(getBaseContext());
        // initiate configuration helper
        if (configHelper == null)
            configHelper = new ConfigHelper(dbHelper);
        // initiate photo manager
        if (photoManager == null)
            photoManager = new PhotoManager(getBaseContext(), dbHelper);
        // initiate battery helper
        if (batteryHelper == null)
            batteryHelper = BatteryHelper.getInstance(getBaseContext());
        // find device owner
        deviceOwner = findDeviceOwner();
        // find active workday
        activeWorkday = findActiveWorkday();
        // find active check in
        activeCheckIn = findActiveCheckIn();
        boolean isFirstLocation = activeWorkday == null || activeWorkday.geocoord == null;
        // initiate geolocation helper
        if (geoHelper == null)
            geoHelper = new GeoHelper(getBaseContext(), dbHelper, this, isFirstLocation);
        // initiate vibrator
        if (vibrator == null)
            vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        // check if application is already authenticated
        authenticated = configHelper.checkIfExists(Configs.AUTHENTICATED);
        // start to watch SMSs trying to find a sms to authenticated
        if (!authenticated && smsHelper == null) {
            // TWW: 27800
            List<String> numbersToWatches = Arrays.asList("27800");
            smsHelper = new SmsHelper(getBaseContext(), this, numbersToWatches);
        } else if (authenticated) {
            setGlobalDeviceHash();
            // start timer to check if is between 8am and 6pm
            setWorkdayAlarms();
            // Try to sync anything pendent
            dbHelper.syncAll();
        }
        // if workday is initiated start to track device
        if (activeWorkday.isInitiated())
            this.start();
        apiClient = ApiClient.getInstance(getBaseContext());
    }

Em sexta-feira, 30 de janeiro de 2015 12:25:00 UTC-2, Geovani **Leia a documentação oficial** de Souza escreveu:
Vc chamou "super.onCreate();"? Fora isso, ajudaria se vc postasse o trecho de código problemático...

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS