Thanks to visit codestin.com
Credit goes to github.com

Skip to content

systemAppearance crashes app when used before application.run #8383

Open
@Whip

Description

@Whip

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 6.3.3
  • Cross-platform modules:
  • Android Runtime: 6.4.1
  • iOS Runtime: 6.4.0
  • Plugin(s):
"dependencies": {
    "@nativescript/theme": "2.3.2",
    "@nstudio/nativescript-cardview": "1.0.0",
    "@nstudio/nativescript-checkbox": "1.0.0",
    "@nstudio/nativescript-floatingactionbutton": "2.0.0",
    "@nstudio/nativescript-loading-indicator": "3.0.2",
    "nativescript-carousel": "6.1.1",
    "nativescript-geolocation": "5.1.0",
    "nativescript-gif": "4.0.2",
    "nativescript-google-places-autocomplete": "1.0.3",
    "nativescript-image-cache-it": "5.0.0-beta.9",
    "nativescript-material-icons": "1.0.3",
    "nativescript-permissions": "1.3.8",
    "nativescript-toasty": "3.0.0-alpha.2",
    "nativescript-ui-dataform": "6.0.0",
    "nativescript-ui-listview": "8.0.1",
    "tns-core-modules": "6.4.1"
  },
  "devDependencies": {
    "nativescript-dev-webpack": "1.5.0",
    "sass": "^1.25.0",
    "scss": "^0.2.4"
  },

Describe the bug
application.systemAppearance() functions runs well after application.run() has executed but before that the app crashes with the following error. I wanted to save the device theme in a global variable so I don't have to run the check again and again in individual pages.

StackTrace:
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function 
TypeError: Cannot read property 'getResources' of undefined
File: (file:///node_modules/@nativescript/core/application/application.js:67:0)

StackTrace: 
get(file:///node_modules/@nativescript/core/application/application.js:67:0)
	at systemAppearance(file:///node_modules/@nativescript/core/application/application.js:197:0)
	at (file:///app/app.js:75:0)
	at ./app.js(file:///data/data/com.nativescript.test/files/app/bundle.js:509:30)
	at __webpack_require__(file:///app/webpack/bootstrap:750:0)
	at checkDeferredModules(file:///app/webpack/bootstrap:43:0)
	at webpackJsonpCallback(file:///app/webpack/bootstrap:30:0)
	at (file:///data/data/com.nativescript.test/files/app/bundle.js:2:57)
	at require(:1:266)


TypeError: Cannot read property 'getResources' of undefined
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6484)
	at android.app.ActivityThread.access$1300(ActivityThread.java:220)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7397)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: com.tns.NativeScriptException: Error calling module function 
TypeError: Cannot read property 'getResources' of undefined
File: (file:///node_modules/@nativescript/core/application/application.js:67:0)

StackTrace: 
get(file:///node_modules/@nativescript/core/application/application.js:67:0)
	at systemAppearance(file:///node_modules/@nativescript/core/application/application.js:197:0)
	at (file:///app/app.js:75:0)
	at ./app.js(file:///data/data/com.nativescript.test/files/app/bundle.js:509:30)
	at __webpack_require__(file:///app/webpack/bootstrap:750:0)
	at checkDeferredModules(file:///app/webpack/bootstrap:43:0)
	at webpackJsonpCallback(file:///app/webpack/bootstrap:30:0)
	at (file:///data/data/com.nativescript.test/files/app/bundle.js:2:57)
	at require(:1:266)


TypeError: Cannot read property 'getResources' of undefined
	at com.tns.Runtime.runModule(Native Method)
	at com.tns.Runtime.runModule(Runtime.java:674)
	at com.tns.Runtime.run(Runtime.java:666)
	at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1183)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6479)
	... 8 more

To Reproduce
in app.js

const application = require("@nativescript/core/application");
const theme = application.systemAppearance();
console.log(theme);
application.run({ moduleName: 'app-root' });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions