Skip to content

Commit

Permalink
Error: java.lang.NullPointerException: Attempt to invoke virtual meth…
Browse files Browse the repository at this point in the history
…od 'boolean android.nfc.Tag.hasTech(int)' on a null object reference #40
  • Loading branch information
EddyVerbruggen committed Aug 17, 2019
1 parent ac862b8 commit b5073e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/nfc.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class NfcIntentHandler {

// every action should map to a different listener you pass in at 'startListening'
if (action === android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED) {
console.log(">> tag: " + tag); // issue 40?
let ndef = android.nfc.tech.Ndef.get(tag);

let ndefJson: NfcNdefData = this.ndefToJSON(ndef);
Expand Down Expand Up @@ -354,13 +353,13 @@ export class Nfc implements NfcApi {

public eraseTag(): Promise<any> {
return new Promise((resolve, reject) => {
let intent = application.android.foregroundActivity.getIntent();
if (intent === null || nfcIntentHandler.savedIntent === null) {
const intent = application.android.foregroundActivity.getIntent() || nfcIntentHandler.savedIntent;
if (!intent) {
reject("Can't erase tag; didn't receive an intent");
return;
}

let tag = nfcIntentHandler.savedIntent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG) as android.nfc.Tag;
let tag = intent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG) as android.nfc.Tag;
let records = new Array.create(android.nfc.NdefRecord, 1);

let tnf = android.nfc.NdefRecord.TNF_EMPTY;
Expand Down Expand Up @@ -389,13 +388,18 @@ export class Nfc implements NfcApi {
reject("Nothing passed to write");
return;
}
let intent = application.android.foregroundActivity.getIntent();
if (intent === null || nfcIntentHandler.savedIntent === null) {
reject("Can not write to tag; didn't receive an intent");

const intent = application.android.foregroundActivity.getIntent() || nfcIntentHandler.savedIntent;
if (!intent) {
reject("Can't write to tag; didn't receive an intent");
return;
}

let tag = nfcIntentHandler.savedIntent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG) as android.nfc.Tag;
let tag = intent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG) as android.nfc.Tag;
if (!tag) {
reject("No tag found to write to");
return;
}

let records = this.jsonToNdefRecords(arg);

Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-nfc",
"version": "4.0.2",
"version": "4.0.3",
"description": "NFC plugin for your NativeScript app",
"main": "nfc",
"typings": "index.d.ts",
Expand Down

0 comments on commit b5073e7

Please sign in to comment.