androidnullpointerexceptionnativescriptauth0tns

Nativescript-auth0 | java.lang.NullPointerException


To begin with , i'm quite new with this so excuse me if i forgot some informations and already thanks for your help.

I'm trying to use nativescript-auth0 to login to my nativescript android app.

First , my tns version is 4.1.2. The version of tns-android is 4.1.3. The version of nativescript-auth0 is 2.0.0.

I followed this link : https://github.com/sitefinitysteve/nativescript-auth0

As they saied , i added to the Android Manifest :

<activity
            android:name="com.auth0.android.provider.RedirectActivity"
            tools:node="replace">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="jarggon.eu.auth0.com"
                    android:pathPrefix="/android/org.nativescript.JarggonTranslatorApp/callback"
                    android:scheme="https" />
            </intent-filter>
        </activity>

In my component i have :

 lock.show().then((res) => {
  console.log('success');
}, function (error) {
  console.log(error);
}); 

With my instance of lock , everything is perfectly fine.

But when i'm running the app by " tns run android " i get this :

JS: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference JS: android.support.v4.content.LocalBroadcastManager.getInstance(LocalBroadcastManager.java:102) JS: com.auth0.android.lock.Lock.initialize(Lock.java:144) JS: com.auth0.android.lock.Lock.access$200(Lock.java:56) JS: com.auth0.android.lock.Lock$Builder.build(Lock.java:236) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:983) JS: com.tns.Runtime.callJSMethod(Runtime.java:970) JS: com.tns.Runtime.callJSMethod(Runtime.java:954) JS: com.tns.Runtime.callJSMethod(Runtime.java:946) JS: com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18) JS: android.app.Activity.performCreate(Activity.java:7041) JS: android.app.Activity.performCreate(Activity.java:7032) JS: android.app.Instrumentation.callActivityOnCre...

I know it's from the console.log of the error in the lock.show() function , but i don't understand why..

I also tried to add a reference.d.ts file in the root and put in it :

/// <reference path="./node_modules/nativescript-auth0/typings/Auth0.ios.d.ts" />
/// <reference path="./node_modules/nativescript-auth0/typings/Lock.ios.d.ts" />

But i get something like 30 errors at runtime like :

node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(2,43): error TS2552: Cannot find name 'NSObject'. Did you mean 'Object'? node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(8,42): error TS2304: Cannot find name 'NSURL'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(10,42): error TS2304: Cannot find name 'NSURL'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(10,58): error TS2304: Cannot find name 'NSURLSession'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(12,153): error TS2304: Cannot find name 'NSDictionary'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(12,195): error TS2304: Cannot find name 'NSError'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(12,208): error TS2304: Cannot find name 'NSDictionary'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(14,45): error TS2304: Cannot find name 'NSURL'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(16,52): error TS2304: Cannot find name 'NSURL'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(16,68): error TS2304: Cannot find name 'NSURLSession'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(18,118): error TS2304: Cannot find name 'NSDictionary'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(18,160): error TS2304: Cannot find name 'NSError'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(20,151): error TS2304: Cannot find name 'NSDictionary'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(20,193): error TS2304: Cannot find name 'NSError'. node_modules/nativescript-auth0/typings/Auth0.ios.d.ts(22,93): error TS2304: Cannot find name 'NSError'.

I don't know what else i can do .. thanks for your help , if you need any information tell me ..


Solution

  • It's resolved. If someone need to know i had to use the loaded event of the GridLayout .. Because the view wasn't ready before i do the instance of the lock even if i used ngAfterViewInit .