Android Question NFCAdvanced error

FormCommander

Member
Licensed User
Longtime User
Hello,
I would like to try the example, but get an error:

Logger connected to: samsung SM-T585
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 38 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.nfc.NfcAdapter.enableForegroundDispatch(android.app.Activity, android.app.PendingIntent, android.content.IntentFilter[], java.lang.String[][])' on a null object reference
at anywheresoftware.b4a.objects.NFC.EnableForegroundDispatch(NFC.java:91)
at b4a.example.main._activity_resume(main.java:415)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

the device has no NFC, can this be the problem ?
regards
Rudolf
 

FormCommander

Member
Licensed User
Longtime User
Hello Erel,
I use the sample without changes. There is the NFC lib version 2.01 checked. Is this sample outdated ?
regards
Rudolf
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is this sample outdated ?
No

You should call NFC.IsSupported to check whether NFC is supported. And only use the Methods if the Device supports NFC.
 
Upvote 0

FormCommander

Member
Licensed User
Longtime User
Hello, thank you, I changed the code now and check if NFC is supported bevore I call this method.
Erel: how to use the internal library instead of NFC lib in the sample ?
regards
Rudolf
 
Upvote 0
Top