EddyVerbruggen / nativescript-nfc

:pencil: NativeScript plugin to discover, read, and write NFC tags
MIT License
84 stars 37 forks source link

Error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.Tag.hasTech(int)' on a null object reference #40

Closed larscifi closed 5 years ago

larscifi commented 5 years ago

Hi, when i try to write an nfc tag on android, the following error occurs:

I´m working with the latest version

[Error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.Tag.hasTech(int)' on a null object reference JS: android.nfc.tech.Ndef.get(Ndef.java:146) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1083) JS: com.tns.Runtime.callJSMethod(Runtime.java:1070) JS: com.tns.Runtime.callJSMethod(Runtime.java:1050) JS: com.tns.Runtime.callJSMethod(Runtime.java:1042) JS: com.tns.gen.org.nativescript.widgets.Async_CompleteCallback.onComplete(Async_CompleteCallback.java:20) JS: org.nativescript.widgets.Async$Http$HttpRequestTask.onPostExecute(Async.java:573) JS: org.nativescript.widgets.Async$Http$1$1.run(Async.java:304) JS: android.os.Handler.handleCallback(Handler.java:789) JS: android.os.Handler.dispatchMessage(Handler.java:98) JS: android.os.Looper.loop(Looper.java:180) JS: android.app.ActivityThread.main(ActivityThread.java:6950) JS: java.lang.reflect.Method.invo...

a-backman commented 5 years ago

Any progress on this issue? I get the same error.

I'm using Nativescript 6.0.2 btw.

Fatfrido commented 5 years ago

I've got the same problem with Nativescript 6.0.0.

EddyVerbruggen commented 5 years ago

Interestingly I can't reproduce this.. how do you trigger it exactly?

Looking at the stacktrace you could try and guard this line; only run that bit of code if tag is not null. You can go into node_modules/nativescript-nfc and give it a go.

EddyVerbruggen commented 5 years ago

I'm just going to assume the aforementioned issue is the problem on your end, and publish 4.0.2 in a bit.

Fatfrido commented 5 years ago

So.. I quickly created a new project just to test the writing here (when an empty tag is discovered it should write a string to it). However, I still get this error. I've also tried to guard the line @EddyVerbruggen mentioned earlier (thanks for your input, btw), but this part of the code is not executed, since I only try to write on empty tags, I guess. I used Nativescript 6.0.0 and tested on Android 9.

EddyVerbruggen commented 5 years ago

@Fatfrido Thx for the repo. Indeed, when writing a tag I can reproduce this error.

EddyVerbruggen commented 5 years ago

@Fatfrido Should be much better with 4.0.3.

Fatfrido commented 5 years ago

@EddyVerbruggen thanks for the quick fix mate. You are awesome :D

a-backman commented 5 years ago

@EddyVerbruggen thanks for the fix!