System.err:TypeError:无法读取未定义的属性“ onNavigatingTo”

时间:2018-08-24 10:43:37

标签: nativescript nativescript-cli

我的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 停止了应用程序,然后使用 tns run android 重新启动了我的应用程序,则该应用程序将成功运行而没有任何错误。

1 个答案:

答案 0 :(得分:3)

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

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

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