android - 无法启动。系统错误 : Calling js method onCreate failed

标签 android windows-10 nativescript emulation

我使用此命令:tns run android --device Pixel_2_API_29 在 android 模拟器上运行我的 NativeScript 项目,但我得到了这个结果:

Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.
Searching for devices...
Starting Android emulator with image Pixel_2_API_29
Waiting for emulator device initialization...
Your application will be deployed only on the device specified by the provided index or identifier.
Running webpack for Android...
clean-webpack-plugin: C:\Users\m\Desktop\JS\NativeScript\new\conFusion\platforms\android\app\src\main\assets\app\**\* has been removed.
File change detected. Starting incremental webpack compilation...

webpack is watching the files…

Hash: 74cf71392c2a31059459
Version: webpack 4.27.1
Time: 8985ms
Built at: 06/13/2019 10:46:07 AM
                                                              Asset       Size   Chunks             Chunk Names
                                   App_Resources/Android/app.gradle  556 bytes           [emitted]
                 App_Resources/Android/src/main/AndroidManifest.xml   1.33 KiB           [emitted]
    App_Resources/Android/src/main/res/drawable-hdpi/background.png   3.42 KiB           [emitted]
          App_Resources/Android/src/main/res/drawable-hdpi/icon.png    6.8 KiB           [emitted]
          App_Resources/Android/src/main/res/drawable-hdpi/logo.png   32.4 KiB           [emitted]
    App_Resources/Android/src/main/res/drawable-ldpi/background.png   1.31 KiB           [emitted]
          App_Resources/Android/src/main/res/drawable-ldpi/icon.png   3.23 KiB           [emitted]
          App_Resources/Android/src/main/res/drawable-ldpi/logo.png   9.95 KiB           [emitted]
    App_Resources/Android/src/main/res/drawable-mdpi/background.png   1.89 KiB           [emitted]
          App_Resources/Android/src/main/res/drawable-mdpi/icon.png   3.42 KiB           [emitted]
          App_Resources/Android/src/main/res/drawable-mdpi/logo.png   15.8 KiB           [emitted]
App_Resources/Android/src/main/res/drawable-nodpi/splash_screen.xml  304 bytes           [emitted]
   App_Resources/Android/src/main/res/drawable-xhdpi/background.png   5.26 KiB           [emitted]
         App_Resources/Android/src/main/res/drawable-xhdpi/icon.png   10.4 KiB           [emitted]
         App_Resources/Android/src/main/res/drawable-xhdpi/logo.png     54 KiB           [emitted]
  App_Resources/Android/src/main/res/drawable-xxhdpi/background.png   10.3 KiB           [emitted]
        App_Resources/Android/src/main/res/drawable-xxhdpi/icon.png   20.3 KiB           [emitted]
        App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png    116 KiB           [emitted]
 App_Resources/Android/src/main/res/drawable-xxxhdpi/background.png   3.87 KiB           [emitted]
       App_Resources/Android/src/main/res/drawable-xxxhdpi/icon.png   73.8 KiB           [emitted]
       App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png    193 KiB           [emitted]
           App_Resources/Android/src/main/res/values-v21/colors.xml  104 bytes           [emitted]
           App_Resources/Android/src/main/res/values-v21/styles.xml  902 bytes           [emitted]
               App_Resources/Android/src/main/res/values/colors.xml  237 bytes           [emitted]
               App_Resources/Android/src/main/res/values/styles.xml   1.68 KiB           [emitted]
                                                          bundle.js     17 KiB   bundle  [emitted]  bundle
                                                       package.json   82 bytes           [emitted]
                                                         runtime.js   29.8 KiB  runtime  [emitted]  runtime
                                                         starter.js   60 bytes           [emitted]
                                                tns-java-classes.js    0 bytes           [emitted]
                                                          vendor.js   5.02 MiB   vendor  [emitted]  vendor
Entrypoint bundle = runtime.js vendor.js bundle.js
[../$$_lazy_route_resource lazy recursive] ../$$_lazy_route_resource lazy namespace object 160 bytes {bundle} [built]
[./app.css] 1.01 KiB {bundle} [built]
[./app/app.component.html] 167 bytes {bundle} [built]
[./app/app.component.ts] 354 bytes {bundle} [built]
[./app/app.module.ts] 1.71 KiB {bundle} [built]
[./app/menu/menu.component.css] 19 bytes {bundle} [built]
[./app/menu/menu.component.html] 1.11 KiB {bundle} [built]
[./app/menu/menu.component.ts] 933 bytes {bundle} [built]
[./app/services/dish.service.ts] 1.29 KiB {bundle} [built]
[./app/services/process-httpmsg.service.ts] 784 bytes {bundle} [built]
[./app/shared/baseurl.ts] 49 bytes {bundle} [built]
[./main.ts] 2.36 KiB {bundle} [built]
[./package.json] 73 bytes {bundle} [optional] [built]
    + 386 hidden modules
Webpack compilation complete. Watching for file changes.
Webpack build done!
Skipping prepare.
Successfully transferred runtime.js on device emulator-5554.
Restarting application on device emulator-5554...
Successfully synced application org.nativescript.conFusion on device emulator-5554.
JS: HMR: Hot Module Replacement Enabled. Waiting for signal.
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.conFusion/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err:
System.err: Error: Template parse errors:
System.err: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
System.err: </ActionBar>
System.err: <StackLayout class="page">
System.err:     [ERROR ->]<ListView [items]="dishes" class="list-group" *ngIf="dishes">
System.err:         <ng-template let-dish="item">
System.err: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
System.err:         </ng-template>
System.err:     </ListView>
System.err:     [ERROR ->]<ActivityIndicator busy="true"  *ngIf="!(dishes || errMess)" width="50" height="50" class="activity-i"): ng:///AppModule/MenuComponent.html@14:4
System.err: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("="!(dishes || errMess)" width="50" height="50" class="activity-indicator"></ActivityIndicator>
System.err:     [ERROR ->]<Label *ngIf="errMess" [text]="'Error: ' + errMess"></Label>
System.err: </StackLayout>"): ng:///AppModule/MenuComponent.html@15:4
System.err: File: "file:///data/data/org.nativescript.conFusion/files/app/vendor.js, line: 21142, column: 12
System.err:
System.err: StackTrace:
System.err:     Frame: function:'ZoneAwareError', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 73853, column: 33
System.err:     Frame: function:'syntaxError', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 11620, column: 17
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 21142, column: 19
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36218, column: 37
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36205, column: 23
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36148, column: 62
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36148, column: 19
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36058, column: 19
System.err:     Frame: function:'then', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 11611, column: 77
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36057, column: 26
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36017, column: 37
System.err:     Frame: function:'push.../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 68387, column: 31
System.err:     Frame: function:'compileNgModuleFactory__PRE_R3__', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 62226, column: 21
System.err:     Frame: function:'push.../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 62435, column: 16
System.err:     Frame: function:'_bootstrapper', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 71945, column: 35
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 72008, column: 19
System.err:     Frame: function:'push.../node_modules/tns-core-modules/data/observable/observable.js.Observable.notify', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 90899, column: 23
System.err:     Frame: function:'notifyLaunch', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 109265, column: 17
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 109187, column: 28
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 109036, column: 14
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 106850, column: 25
System.err:
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260)
System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
System.err:     at android.os.Looper.loop(Looper.java:214)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:7319)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
System.err: Caused by: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err:
System.err: Error: Template parse errors:
System.err: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
System.err: </ActionBar>
System.err: <StackLayout class="page">
System.err:     [ERROR ->]<ListView [items]="dishes" class="list-group" *ngIf="dishes">
System.err:         <ng-template let-dish="item">
System.err: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
System.err:         </ng-template>
System.err:     </ListView>
System.err:     [ERROR ->]<ActivityIndicator busy="true"  *ngIf="!(dishes || errMess)" width="50" height="50" class="activity-i"): ng:///AppModule/MenuComponent.html@14:4
System.err: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("="!(dishes || errMess)" width="50" height="50" class="activity-indicator"></ActivityIndicator>
System.err:     [ERROR ->]<Label *ngIf="errMess" [text]="'Error: ' + errMess"></Label>
System.err: </StackLayout>"): ng:///AppModule/MenuComponent.html@15:4
System.err: File: "file:///data/data/org.nativescript.conFusion/files/app/vendor.js, line: 21142, column: 12
System.err:
System.err: StackTrace:
System.err:     Frame: function:'ZoneAwareError', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 73853, column: 33
System.err:     Frame: function:'syntaxError', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 11620, column: 17
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 21142, column: 19
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36218, column: 37
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36205, column: 23
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36148, column: 62
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36148, column: 19
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36058, column: 19
System.err:     Frame: function:'then', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 11611, column: 77
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36057, column: 26
System.err:     Frame: function:'push.../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 36017, column: 37
System.err:     Frame: function:'push.../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 68387, column: 31
System.err:     Frame: function:'compileNgModuleFactory__PRE_R3__', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 62226, column: 21
System.err:     Frame: function:'push.../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 62435, column: 16
System.err:     Frame: function:'_bootstrapper', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 71945, column: 35
System.err:     Frame: function:'', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 72008, column: 19
System.err:     Frame: function:'push.../node_modules/tns-core-modules/data/observable/observable.js.Observable.notify', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 90899, column: 23
System.err:     Frame: function:'notifyLaunch', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 109265, column: 17
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 109187, column: 28
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 109036, column: 14
System.err:     Frame: function:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.conFusion/files/app/vendor.js', line: 106850, column: 25
System.err:
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1083)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1070)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1050)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1042)
System.err:     at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:19)
System.err:     at android.app.Activity.performCreate(Activity.java:7783)
System.err:     at android.app.Activity.performCreate(Activity.java:7772)
System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
System.err:     ... 11 more

我知道模拟器存在于我的电脑中,它会在我运行上述命令后启动,但在屏幕上显示许多错误。因为我是 NativeScript 的新手,只是按照视频教程无法理解问题是什么?我该如何解决?

编辑: 这是 menu.component.html 文件的内容:

<ActionBar title="Menu" class="action-bar">
</ActionBar>
<StackLayout class="page">
    <ListView [items]="dishes" class="list-group" *ngIf="dishes">
        <ng-template let-dish="item">
            <StackLayout orientation="horizontal" class="list-group-item">
                <Image row="0" col="0" rowSpan="2" height="108" width="108"  [src]="BaseURL + dish.image" class="thumb p-16"></Image>
                <GridLayout class="list-group-item" rows="auto *" columns="*">
                    <Label row="0" col="0" [text]="dish.name" class="list-group-item-heading"></Label>
                    <Label row="1" col="0" class="list-group-item-text" [text]="dish.description"></Label>   
                </GridLayout>
            </StackLayout>
        </ng-template>
    </ListView>
    <ActivityIndicator busy="true"  *ngIf="!(dishes || errMess)" width="50" height="50" class="activity-indicator"></ActivityIndicator>
    <Label *ngIf="errMess" [text]="'Error: ' + errMess"></Label>
</StackLayout>

编辑2: 我使用评论中的指南解决了之前的问题,但我在模拟器屏幕上看到了这个新错误:

No ErrorHandler. Is platform module (BrowserModule) included?

Error: No ErrorHandler. Is platform module (BrowserModule) included?
    at file:///data/data/org.nativescript.conFusion/files/app/vendor.js:62401:23 [angular]
    at Object.onInvoke (file:///data/data/org.nativescript.conFusion/files/app/vendor.js:61906:33) [angular]
    at NgZone.push.../node_modules/@angular/core/fesm5/core.js.NgZone.run (file:///data/data/org.nativescript.conFusion/files/app/vendor.js:61820:28) [<root>]
    at PlatformRef.push.../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModuleFactory (file:///data/data/org.nativescript.conFusion/files/app/vendor.js:62396:23) [<root>]
    at file:///data/data/org.nativescript.conFusion/files/app/vendor.js:62436:59 [<root>]
    at file:///data/data/org.nativescript.conFusion/files/app/vendor.js:73438:34 [<root>]
    at Function.drainMicroTaskQueue (file:///data/data/org.nativescript.conFusion/files/app/vendor.js:73150:35) [<root>]

最佳答案

您必须在您的 NgModule 中包含 CommonModule,这实际上启用了对 ngIf 等通用指令的支持。

另外很明显,您不能导入 BrowserModule,您没有在此处的浏览器中运行您的应用程序,但等效项是 NativeScriptModule。

关于android - 无法启动。系统错误 : Calling js method onCreate failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56574459/

相关文章:

Android 4.4 KitKat chromium 错误:未实现 virtual void android_webview::AwAutofillManagerDelegate::UpdateAutofillPopupDataListValues

android - 在 Android 中获取图片的一部分?

javascript - 如何将跳转列表添加到 UWP Windows 10 应用程序——用 JavaScript 编写

android - Nativescript:如何以编程方式禁用/启用 ScrollView 滚动?

java - 我无法恢复到上次 Activity

android - 使用 multidex 和 Dagger 2 时,Application 对象中缺少函数

powershell - 如何在 powershell 中找到 Windows 10 上的 Microsoft Edge 版本?

c# - 在 UWP Windows 10 中找不到位图类

android - native 模块在 NativeScript 中无法正常工作

java - Nativescript + Genymotion : App not starting up on simulator - Execution failed for task ':buildMetadata'