question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@nativescript/geolocation] - Error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

See original GitHub issue

The following exception is being thrown whenever I call the enableLocationRequest() method.

 Error: Uncaught (in promise): Error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
JS: _systemDialogWillShow(file:///data/user/0/<directory>/files/app/vendor.js:145569:61)
JS:     at (file:///data/user/0/<directory>/files/app/vendor.js:145468:14)
JS:     at ZoneAwarePromise(file:///data/user/0/<directory>/files/app/vendor.js:146586:29)
JS:     at enableLocationRequest(file:///data/user/0/<directory>/files/app/vendor.js:145465:12)
JS:     at (file:///data/user/0/<directory>/files/app/bundle.js:441:79)
JS:     at ZoneDelegate.invoke(file:///data/user/0/<directory>/files/app/vendor.js:146072:26)
JS:     at onInvoke(file:///data/user/0/<directory>/files/app/vendor.js:73479:33)
JS:     at ZoneDelegate.invoke(file:///data/user/0/<directory>/files/app/vendor.js:146071:32)
JS:     at...

In the ngOnInit of my component, I’m calling the following piece of code

import { enableLocationRequest, isEnabled } from '@nativescript/geolocation';

...

isEnabled().then((enabled: boolean) => {
    if (!enabled) {
        return enableLocationRequest(true, true);
    }
});

This is happening on Android 11. Below are my gradle files and the permissions I have in the AndroidManifest.xml

android {
  defaultConfig {
    minSdkVersion 22
    generatedDensities = []
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Am I missing something? This is happening every time that method is called, and according to the docs that’s all that is required to request location. Thanks in advance.

Package.json include the following versions

"@angular/animations": "~11.2.7",
    "@angular/cdk": "10.2.5",
    "@angular/common": "~11.2.7",
    "@angular/compiler": "~11.2.7",
    "@angular/core": "~11.2.7",
    "@angular/forms": "~11.2.7",
    "@angular/material": "10.2.5",
    "@angular/platform-browser": "~11.2.7",
    "@angular/platform-browser-dynamic": "~11.2.7",
    "@angular/router": "~11.2.7",
    "@nativescript/angular": "~11.8.0",
    "@nativescript/core": "~8.0.0",
    "@nativescript/geolocation": "7.2.1",
    "@nativescript/theme": "3.0.0",
    "nativescript-permissions": "1.3.11",
    "reflect-metadata": "0.1.13",
    "rxjs": "~6.6.7",
    "tslib": "2.0.3",
    "zone.js": "~0.11.1"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Cersincommented, Oct 3, 2021

@yencolon i have this error: JS: Error: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean android.app.Activity.shouldShowRequestPermissionRationale(java.lang.String)’ on a null object reference

0reactions
canmertccommented, Dec 23, 2021

Upgraded the plugin to v8.0.1. But still throws the same error

JS: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.app.Activity.shouldShowRequestPermissionRationale(java.lang.String)' on a null object reference

Workaround: Checking if there is a foreground activity on Android, before requesting the location has cleared the error.

if (isAndroid && !Application.android.foregroundActivity) {
    return
}
geolocation.enableLocationRequest();
Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException: Attempt to invoke virtual method ...
NullPointerException : Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference ...
Read more >
Attempt to invoke virtual method 'boolean java.lang ... - YouTube
Android : NullPointerException : Attempt to invoke virtual method ' boolean java. lang. String.equalsIgnoreCase( java. lang. String )' on a null ...
Read more >
Attempt to invoke virtual method 'boolean java.lang.String ...
NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference #183.
Read more >
Attempt to invoke virtual method ''boolean java.lang.String ...
NullPointerException : Attempt to invoke virtual method ''boolean java.lang.String.equals(java.lang.Object)'' on a null object reference at org.mozilla.gecko.
Read more >
Attempt to invoke virtual method 'boolean java.lang.String ...
NullPointerException : Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found