deokgyuhan / flutter_nfc_hce

MIT License
6 stars 6 forks source link

Error to write NDEF message openFileInput on a null object reference #5

Open wh120 opened 5 months ago

wh120 commented 5 months ago

Hello I try to start HCE on my Samsung mobile (Galaxy S21+) First time it is worked for me many times But now do not work and I get this error

I/TEST    (10352): ---------------------->isSecureNfcEnabled: false
I/TEST    (10352): ---------------------->isNfcHceSupported: true
I/flutter (10352): success
W/System.err(10352): java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileInputStream android.content.Context.openFileInput(java.lang.String)' on a null object reference
W/System.err(10352):    at android.content.ContextWrapper.openFileInput(ContextWrapper.java:258)
W/System.err(10352):    at com.novice.flutter_nfc_hce.KHostApduService$Companion.readNdefMessageFromFile(KHostApduService.kt:360)
W/System.err(10352):    at com.novice.flutter_nfc_hce.KHostApduService.<init>(KHostApduService.kt:110)
W/System.err(10352):    at java.lang.Class.newInstance(Native Method)
W/System.err(10352):    at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
W/System.err(10352):    at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:74)
W/System.err(10352):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:5073)
W/System.err(10352):    at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
W/System.err(10352):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2506)
W/System.err(10352):    at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err(10352):    at android.os.Looper.loopOnce(Looper.java:230)
W/System.err(10352):    at android.os.Looper.loop(Looper.java:319)
W/System.err(10352):    at android.app.ActivityThread.main(ActivityThread.java:8919)
W/System.err(10352):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err(10352):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
W/System.err(10352):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
I/HostApduService(10352): createNdefRecord(): 
W/System.err(10352): java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileInputStream android.content.Context.openFileInput(java.lang.String)' on a null object reference
W/System.err(10352):    at android.content.ContextWrapper.openFileInput(ContextWrapper.java:258)
W/System.err(10352):    at com.novice.flutter_nfc_hce.KHostApduService$Companion.readNdefMessageFromFile(KHostApduService.kt:360)
W/System.err(10352):    at com.novice.flutter_nfc_hce.KHostApduService.<init>(KHostApduService.kt:121)
W/System.err(10352):    at java.lang.Class.newInstance(Native Method)
W/System.err(10352):    at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
W/System.err(10352):    at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:74)
W/System.err(10352):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:5073)
W/System.err(10352):    at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
W/System.err(10352):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2506)
W/System.err(10352):    at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err(10352):    at android.os.Looper.loopOnce(Looper.java:230)
W/System.err(10352):    at android.os.Looper.loop(Looper.java:319)
W/System.err(10352):    at android.app.ActivityThread.main(ActivityThread.java:8919)
W/System.err(10352):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err(10352):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
W/System.err(10352):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
I/onCreate()(10352): -> ndefMessage initial value: 
I/HostApduService(10352): createNdefRecord(): eyJwaG9uZU51bWJlciI6Iis5NzE1MDU2NTcyODMiLCJuYW1lIjoiTWhkIFdhZWwiLCJhdmF0YXJJbWFnZSI6IiJ9
I/HostApduService(10352): onStartCommand() | NDEFNdefMessage [NdefRecord tnf=1 type=54 id=E104 payload=02656E65794A77614739755A55353162574A6C63694936496973354E7A45314D4455324E5463794F444D694C434A755957316C496A6F695457686B494664685A5777694C434A68646D463059584A4A6257466E5A53493649694A39]
I/ViewRootImpl@ef99c00[MainActivity](10352): ViewPostIme pointer 0
deokgyuhan commented 5 months ago

Hello, thank you for your interest in the project.

In the initial version of the plugin, the tag contents were stored in memory, and the tag contents were recorded when the app was closed and restarted.

However, due to a request to record tag contents in permanent storage and read the tag contents from a file when the app starts, this feature has been applied to the currently published plugin.

After testing again, we found that if there is no file initially, a message is displayed as an exception. This issue does not affect the normal operation of NFC HCE.

I will work to improve this in future updates.

Thank you once again. Have a great day and good luck!