RadListView itemTap产生“调用js方法onItemClick失败”错误页面

时间:2018-10-10 16:09:12

标签: android angular nativescript angular2-nativescript

我有一个RadListView,显示从服务器加载的项目列表。我想点击一个项目,然后转到详细信息页面。当我点击列表中的任意位置时,我总是得到相同的黑色错误页面。

这里是填充它的组件。

import { RadListView, ListViewEventData } from "nativescript-ui-listview";
...

...
public onListLoaded(args: ListViewEventData) {

    this.updateService.getReports()
    .subscribe(
        (data) => {              
            console.log("report data in reports component onListLoaded = "+JSON.stringify(data));  
            this._reports = new ObservableArray<Report>();
            this._tempreports = new ObservableArray<Report>();

            if (data["reports"]=="No Reports") {                 
                // No reports to show
            } else {  
                var status_text;
                var status_class;
                for (let i = 0; i < data.reportid.length; i++) {
                    var status_codes=this.displayReportStatus(data.report_status[i]);
                    status_text=status_codes[0];
                    status_class=status_codes[1];

                    this._tempreports.push(new Report(data.reportid[i], data.report_name[i], data.report_status[i], data.report_value[i], status_text, status_class, data.report_justification));
                }
                this._reports = this._tempreports;
                this.isLoading=false;
            }                
        },
        (error) => alert("Problems...")
   ); 
}

这是模板:

<GridLayout orientation="vertical" tkExampleTitle tkToggleNavButton>
<RadListView class="radListView_reports" [items]="reports" (loaded)="onListLoaded($event)" (itemTap)="onReportItemTap($event)">
    <ng-template tkListItemTemplate let-item="item">
        <StackLayout class="itemTemplateStackLayout" orientation="vertical">
            <StackLayout class="reportStackLayout" orientation="vertical">                        
                <Label class="labelName blue_text bold_text list-group-item" [text]="item.report_name"></Label>

                <GridLayout class="reportDetailsGridLayout" columns="*, *">
                    <Label row="0" col="0" horizontalAlignment="left" [class]="item.status_class" class="labelStatus"  [text]="item.status_text" textWrap="true"></Label>
                    <Label row="0" col="1" horizontalAlignment="right" class="labelValue green_text bold_text" [text]="item.report_value" textWrap="true"></Label>
                </GridLayout>

            </StackLayout>
        </StackLayout>
    </ng-template>         
</RadListView>
</GridLayout>

这是整个错误页面的内容:

10-10 16:49:58.253 31558 31558 E MessageQueue-JNI:      at com.tns.Runtime.callJSMethodNative(Native Method)
10-10 16:49:58.253 31558 31558 E MessageQueue-JNI:      at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
10-10 16:49:58.253 31558 31558 E MessageQueue-JNI:      at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
10-10 16:49:58.253 31558 31558 E MessageQueue-JNI:      at com.tns.Runtime.callJSMethod(Runtime.java:970)
10-10 16:49:58.253 31558 31558 E MessageQueue-JNI:      at com.tns.Runtime.callJSMethod(Runtime.java:954)
10-10 16:49:58.253 31558 31558 E MessageQueue-JNI:      at com.tns.Runtime.callJSMethod(Runtime.java:946)
10-10 16:49:58.260 31558 31558 E AndroidRuntime:        at com.tns.Runtime.callJSMethodNative(Native Method)
10-10 16:49:58.260 31558 31558 E AndroidRuntime:        at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
10-10 16:49:58.260 31558 31558 E AndroidRuntime:        at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
10-10 16:49:58.260 31558 31558 E AndroidRuntime:        at com.tns.Runtime.callJSMethod(Runtime.java:970)
10-10 16:49:58.260 31558 31558 E AndroidRuntime:        at com.tns.Runtime.callJSMethod(Runtime.java:954)
10-10 16:49:58.260 31558 31558 E AndroidRuntime:        at com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err: com.tns.NativeScriptException:
System.err: Calling js method onItemClick failed
System.err:
System.err: TypeError: listView._listViewAdapter.isGroupHeader is not a function
System.err: File: "file:///data/data/org.nativescript.myApp/files/app/tns_modules/nativescript-ui-listview/ui-listview.js, line: 539, column: 62
System.err:
System.err: StackTrace:
System.err:     Frame: function:'onItemClick', file:'file:///data/data/org.nativescript.myApp/files/app/tns_modules/nativescript-ui-listview/ui-listview.js', line: 539, column: 63
System.err:
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:970)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:954)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err:     at com.tns.gen.com.telerik.widget.list.RadListView_ItemClickListener.onItemClick(RadListView_ItemClickListener.java:17)
System.err:     at com.telerik.widget.list.RadListView.notifyOnTapUp(RadListView.java:723)
System.err:     at com.telerik.widget.list.ListViewGestureListener.onTapUp(ListViewGestureListener.java:175)
System.err:     at com.telerik.widget.list.ListViewGestureListener.onSingleTapUp(ListViewGestureListener.java:274)
System.err:     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:656)
System.err:     at com.telerik.widget.list.ListViewGestureListener.onTouchEvent(ListViewGestureListener.java:149)
System.err:     at com.telerik.widget.list.RadListView.onTouchEvent(RadListView.java:544)
System.err:     at android.view.View.dispatchTouchEvent(View.java:12540)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3153)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2829)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3159)
System.err:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2844)
System.err:     at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:601)
System.err:     at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1871)
System.err:     at android.app.Activity.dispatchTouchEvent(Activity.java:3384)
System.err:     at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:563)
System.err:     at android.view.View.dispatchPointerEvent(View.java:12788)
System.err:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5675)
System.err:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5470)
System.err:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4963)
System.err:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5016)
System.err:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4982)
System.err:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5119)
System.err:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4990)
System.err:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5176)
System.err:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4963)
System.err:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5016)
System.err:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4982)
System.err:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4990)
System.err:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4963)
System.err:     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7741)
System.err:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7681)
System.err:     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7642)
System.err:     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7852)
System.err:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:197)
System.err:     at android.os.MessageQueue.nativePollOnce(Native Method)
System.err:     at android.os.MessageQueue.next(MessageQueue.java:325)
System.err:     at android.os.Looper.loop(Looper.java:142)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6944)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
ActivityManager: Process org.nativescript.myApp (pid 31558) has died: fore TOP (202,1058)
ActivityManager: setHasOverlayUi called on unknown pid: 31558

如果我剥离模板,则会出现相同的错误,例如。如果我用单个<Label>替换ng-template。而且,如果我从<RadListView>中删除了(itemTap)=“ onReportItemTap($ event)”。

有什么想法会导致这种情况吗?谢谢。

========= 编辑-对不起,我已经离开了几个星期。

@Narendra Mongiya-我认为这是一个不同的问题,所以我认为最好创建一个新问题。

在此RadListView上的任意位置点击都会出现错误屏幕。

以下是一些错误文字

An uncaught Exception occurred on "main" thread.
com.tns.NativeScriptException: 
Calling js method onItemClick failed

TypeError: listView._listViewAdapter.isGroupHeader is not a function
File: "file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-ui-listview/ui-listview.js, line: 539, column: 62

StackTrace: 
Frame: function:'onItemClick', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-ui-listview/ui-listview.js', line: 539, column: 63


at com.tns.Runtime.callJSMethodNative(Native Method)
at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
at com.tns.Runtime.callJSMethod(Runtime.java:970) etc...

我删除了onReportItemTap调用。现在是RadListView:

    <RadListView [items]="reports" (loaded)="onListLoaded($event)">
        <ng-template tkListItemTemplate let-item="item">
        <StackLayout class="itemTemplateStackLayout" orientation="vertical">
                <StackLayout class="reportStackLayout" orientation="vertical">

                    <Label class="labelName blue_text bold_text list-group-item" [text]="item.report_name"></Label>

                    <GridLayout class="reportDetailsGridLayout" columns="*, *">
                        <Label row="0" col="0" horizontalAlignment="left" [class]="item.status_class" class="labelStatus"  [text]="item.status_text" textWrap="true"></Label>
                        <Label row="0" col="1" horizontalAlignment="right" class="labelValue green_text bold_text" [text]="item.report_value" textWrap="true"></Label>
                    </GridLayout>

                </StackLayout>
        </StackLayout>
    </ng-template>         
</RadListView>

以及组件代码:

    public onListLoaded(args: ListViewEventData) {
    console.log("In onListLoaded");
    this.updateService.getReports()
    .subscribe(
        (data) => {              
            console.log("report data in reports component onListLoaded = "+JSON.stringify(data));  
            this._reports = new ObservableArray<Report>();
            this._tempreports = new ObservableArray<Report>();

            if (data["reports"]=="No Reports") {                 
                // No reports to show
            } else {  
                var status_text;
                var status_class;
                for (let i = 0; i < data.reportid.length; i++) {
                    var status_codes=this.displayReportStatus(data.report_status[i]);
                    status_text=status_codes[0];
                    status_class=status_codes[1];

                    this._tempreports.push(new Report(data.reportid[i], data.report_name[i], data.report_status[i], data.report_value[i], status_text, status_class, data.report_justification));
                }
                this._reports = this._tempreports;

                this.isLoading=false;

                console.log("isLoading="+this.isLoading);   

            }                
        },
        (error) => alert("Problems...")
   ); 
}

public get reports(): ObservableArray<Report> {
    return this._reports;
}

现在没有itemTap侦听器,但是在按住RadListView的屏幕上点击会产生上面的错误页面。有任何想法吗? TIA

1 个答案:

答案 0 :(得分:0)

由于某种原因,看起来处理程序不喜欢参数。我在itemTap事件中遇到了同样的问题。所以我删除了方法参数:

(itemTap)="onReportItemTap()"

希望对您有帮助。