EddyVerbruggen / nativescript-barcodescanner

🔎 NativeScript QR / barcode (bulk)scanner plugin
MIT License
293 stars 73 forks source link

Cannot read property \'getApplicationContext\' of undefined' #249

Open jakubstankowski opened 4 years ago

jakubstankowski commented 4 years ago

Hi, when i want start my vue-nativescript aplication i get error Cannot read property \'getApplicationContext\' of undefined'

i use this version native script: "@nativescript/core": "^7.0.3", and this nativescript-barcodescanner - "nativescript-barcodescanner": "^4.0.1",

there is my code: https://codesandbox.io/s/nativescript-vue-web-template-forked-iyjci

every logic is available in main.js, and in components > App.vue

I used Android 7 +

thanks for help!

EddyVerbruggen commented 4 years ago

That's usually a symptom of invoking the plugin too early. Can you wait until after the app has fully started?

jakubstankowski commented 4 years ago

thanks for response!

i add this two solution for delay starting functionality, first i add a showButton flag to showing button, second in scanQrCode function i used setTimeout, unfortunetely this is not helping, i still get the same error

<Button v-if="showButton" class="btn btn-outline" text="Scan QR code" @tap="scanQrCode"/>

mounted() { this.showButton = true; },

scanQrCode() { setTimeout(() => { var barcodescanner = new BarcodeScanner(); barcodescanner.scan({ //basic options } ); }, 3000) },

this code is available here `

jakubstankowski commented 4 years ago

@EddyVerbruggen do you have some solution for this ?

MarioCat commented 4 years ago

Hi, I have the same issue. I did not try yet but I think that the problem is due to the new version : 4.0.1

Try downgrading to version 3.4.2

EDIT :

I have tried downgrading and it worked for me !

jakubstankowski commented 4 years ago

@MarioCat which version of nativescript you have ? Because i have 7.0.9 and now i get this error: 'No scan: TypeError: Cannot read property \'client\' of undefined'

MarioCat commented 4 years ago

@jakubstankowski I also have 7.0.9

vincent7q commented 3 years ago

Same Error with below environments:

  1. Error: Cannot read property \'getApplicationContext\' of undefined @nativescript/core: 7.0.11 nativescript-barcodescanner: 4.0.1

  2. Error: Cannot read property \'client\' of undefined @nativescript/core: 7.0.11 nativescript-barcodescanner: 3.4.2

Solved by building and deploy with Apk

vincent7q commented 3 years ago

The error only happen on Preview. After build and install the apk (android) on mobile and works fine