chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
704 stars 550 forks source link

nfc.write sometimes succeed and sometimes fail #441

Open Amanda1995pig opened 3 years ago

Amanda1995pig commented 3 years ago

Hello, in my ionic5 Android app. I use nfc.write() sometimes succeed but sometimes fail . It alert me " instanceAttempt to invoke virtual method 'android.os.Parcelable android.content.Intent.getParcelableExtra(java.lang.String)' on a null object reference"

this is my code: -----------------------------------------start------------------------ async writeNfc(i) { this.nfc.addTagDiscoveredListener(() => { let message = this.ndef.textRecord('hello,world'); this.nfc.write([message]).then( () => { console.log('ok') }, error => { console.log(error) } ) }, (err) => { console.error(err); }).subscribe((event) => { console.log(event)

});

} --------------------------------------end----------------------------

Hope to get help,Thanks a lot

yaroslavnosenko commented 3 years ago

I have something similar: E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1 Process: io.ionic.starter, PID: 23572 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.Tag.hasTech(int)' on a null object reference at android.nfc.tech.Ndef.get(Ndef.java:146) at com.chariotsolutions.nfc.plugin.NfcPlugin.lambda$writeNdefMessage$2(NfcPlugin.java:350) at com.chariotsolutions.nfc.plugin.-$$Lambda$NfcPlugin$V4Q2BP7F_8EoqcyBcDBJ2XVT1tY.run(Unknown Source:6) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919)