X-Guard / react-native-flic2

Use Flic 2 within your React Native application with ease.
Other
8 stars 9 forks source link

Unable to create service nl.xguard.flic2.service.Flic2Service #23

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi guys , i'm having a problem calling to isInitialized() method , when I call it , my app crashes , i've looked into Android studio and i get the following error , i'm currently using version 0.3.16.

That's the function that crashes tha app: `const initManager = () => { console.log("initManager")

if (Flic2.isInitialized() === true) {
    console.log("Manager already initialized")
}  

} `

And the error:

java.lang.RuntimeException: Unable to create service nl.xguard.flic2.service.Flic2Service: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference at android.app.ActivityThread.handleCreateService(ActivityThread.java:3545) at android.app.ActivityThread.access$1300(ActivityThread.java:200) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1667) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6692) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference at nl.xguard.flic2.service.Flic2Service.onCreate(Flic2Service.java:65) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3533) at android.app.ActivityThread.access$1300(ActivityThread.java:200)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1667)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:6692)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

Thanks in advance 👍

wesdewitte commented 3 years ago

Hello @spozap, that is probably because flic lib needs some time to startup. Could you test the following code:

if (typeof Flic2.isInitialized === 'function' && Flic2.isInitialized() === true) {
    // its initialized
  } else {
   // listen for it to be initialized
    Flic2.addListener('managerInitialized', this.onInitializedFunction);
  }

We also used this in the example code. I agree the documentation needs an update. I've made a ticket to solve this problem. Thanks for noticing the issue.

ghost commented 3 years ago

I get the same error with that code. I'll wait then to be fixed , tysm!

wesdewitte commented 3 years ago

Oke, do you have some more information for us? Like OS, device, package version etc.

Also could you provide us some more code that you used. So we can investigate what's wrong

ghost commented 3 years ago

Device : Xiaomi Mi A2 (Android) Package version : 8.0.0

Code Involved on the method :

FlicManager.js const initManager = () => { console.log("initManager") if (typeof Flic2.isInitialized === 'function' && Flic2.isInitialized() === true) { // its initialized } else { // listen for it to be initialized Flic2.addListener('managerInitialized', this.onInitializedFunction); } }

App.js :

` const App = () => {

//const result = Permission.requestMultiple([PERMISSION_TYPE.location]); FlicManager.initManager()

return(

console.log("ASDAS")}> panic-button Botón conectado No hay botones conectados

); `

wesdewitte commented 3 years ago

@spozap Oke, i meant the version of the flic 2 library. Could you check with https://github.com/X-Guard/react-native-flic2-example what the differences are? The installation was successful? Try clean your project, this might be a cache problem.

Let us know what you find.

ghost commented 3 years ago

I solved it , was because I've had another service working on , my bad. I'll close the issue , thanks guys!