0

我的 nativescript 应用程序在第一次运行时成功运行,没有任何错误,但是当我保存任何文件而没有任何更改或小的更改时,我的应用程序崩溃并显示以下信息。

08-24 13:32:36.684 3595 3595 E AndroidRuntime: at com.tns.Runtime.callJSMethodNative(Native Method) 08-24 13:32:36.684 3595 3595 E AndroidRuntime: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) 08-24 13:32:36.684 3595 3595 E AndroidRuntime:
at com.tns.Runtime.callJSMethodImpl(Runtime.java:996) 08-24 13:32:36.684 3595 3595 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:983) 08-24 13:32:36.684 3595 3595 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:967) 08-24
13:32:36.684 3595 3595 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:959) System.err: com.tns.NativeScriptException: System.err: Calling js method onViewAttachedToWindow failed System.err: System.err: TypeError: Cannot read property 'onNavigatingTo'
of undefined System.err: File: "file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js, line: 262, column: 36 System.err: System.err: StackTrace: System.err: Frame: function:'FrameBase._onNavigatingTo',
file:'file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 262, column: 37 System.err: Frame: function:'FrameBase.performNavigation', file:'file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js',
line: 234, column: 14 System.err: Frame: function:'FrameBase._processNextNavigationEntry', file:'file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 227, column: 22 System.err: Frame: function:'Frame._processNextNavigationEntry',
file:'file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 138, column: 58 System.err: Frame: function:'Frame._onAttachedToWindow', file:'file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame.js',
line: 114, column: 14 System.err: Frame: function:'AttachListener.onViewAttachedToWindow', file:'file:///data/data/org.nativescript.TekmoTs/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 38, column: 27 System.err: System.err: at com.tns.Runtime.callJSMethodNative(Native
Method) System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:996) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:983) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:967)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:959) System.err: at com.tns.gen.java.lang.Object_frame_32_36_AttachListener.onViewAttachedToWindow(Object_frame_32_36_AttachListener.java:17) System.err: at android.view.View.dispatchAttachedToWindow(View.java:18358)
System.err: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397) System.err: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404) System.err: at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
System.err: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761) System.err: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460) System.err: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183) System.err:
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:761) System.err: at android.view.Choreographer.doFrame(Choreographer.java:696) System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
System.err: at android.os.Handler.handleCallback(Handler.java:873) System.err: at android.os.Handler.dispatchMessage(Handler.java:99) System.err: at android.os.Looper.loop(Looper.java:193) System.err: at android.app.ActivityThread.main(ActivityThread.java:6669)
System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

app-root.xml 文件内容如下:

<Frame defaultPage="views/contact-us/contact-us">
</Frame>

文件结构如下: ├───app │ ├───App_Resources │ │ ├───Android │ │ └───iOS │ └───views │ ├───about │ ├───contact-us │ └───home ├───hooks ...

contact-us.xml 文件的内容也如下:

<Page xmlns="http://www.nativescript.org/tns.xsd" navigatingTo="onNavigatedTo"> <ScrollView> <StackLayout> <Label text="Contact us by submitting a message below." textWrap="true" />
<TextField hint="Enter a subject..." />
<TextView hint="Enter a Message..."/> <Button text="Submit" tap="onTap" /> </StackLayout> </ScrollView> </Page>

不是:如果我用ctrl+c和 y停止应用程序,然后用tns run android重新启动我的应用程序,它会成功运行而没有任何错误。

4

1 回答 1

3

我通过完全删除平台文件夹并使用tns run android重新运行应用程序解决了我的问题。

好的,我发现了导致此问题的真正错误,每当我将 app-root.xml'e defaultPage 属性更改为另一个页面时都会发生错误。我认为这是 nativescript watch 的问题。

在应用程序运行时将 app-root.xml 的 defaultPage 属性更改为另一个页面会使应用程序崩溃。

于 2018-08-24T10:56:17.890 回答