我一直试图实施一周的侧面提取器,我跟踪了文档中的所有内容,当我滑动屏幕时,它抛出了这个不友好的异常。但问题可能是ViewChild,因为this.sidedrawer未定义。 (the problem issued in the GitHub and there is a solution but neither of them works) 我使用角度,所以这是我拥有的组件:
<ActionBar class="action-bar">
<Label class="action-bar-title" text="Restaurant List Nearby"></Label>
<button text="List Mode" (tap)="enableListMode()"></button>
</ActionBar>
<RadSideDrawer tkExampleTitle tkToggleNavButton >
<StackLayout tkDrawerContent class="sideStackLayout" >
<StackLayout class="sideTitleStackLayout">
<Label text="Navigation Menu"></Label>
</StackLayout>
<StackLayout class="sideStackLayout">
<Label text="Primary" class="sideLabel sideLightGrayLabel"></Label>
<Label text="Social" class="sideLabel"></Label>
<Label text="Promotions" class="sideLabel"></Label>
<Label text="Labels" class="sideLabel sideLightGrayLabel"></Label>
<Label text="Important" class="sideLabel"></Label>
<Label text="Starred" class="sideLabel"></Label>
<Label text="Sent Mail" class="sideLabel"></Label>
<Label text="Drafts" class="sideLabel"></Label>
</StackLayout>
<Label text="Close Drawer" color="lightgray" padding="10" style="horizontal-align: center" (tap)="onCloseDrawerTap()"></Label>
</StackLayout>
<StackLayout tkMainContent class="page">
<MapView></MapView>
</StackLayout>
</RadSideDrawer>
和代码:
import { Component, OnInit, ChangeDetectorRef,ViewChild } from '@angular/core';
import {registerElement} from "nativescript-angular/element-registry";
import { Router } from "@angular/router";
registerElement("MapView", () => require("nativescript-google-maps-sdk").MapView);
import { RadSideDrawerComponent, SideDrawerType } from "nativescript-ui-sidedrawer/angular";
import { RadSideDrawer } from 'nativescript-ui-sidedrawer';
@Component({
selector: 'app-map-mode',
moduleId: module.id,
templateUrl: './map-mode.component.html',
styleUrls: ['./map-mode.component.css']
})
export class MapModeComponent implements OnInit {
private _mainContentText: string;
constructor(private _changeDetectionRef: ChangeDetectorRef,
private router: Router) { }
@ViewChild(RadSideDrawerComponent) public drawerComponent: RadSideDrawerComponent;
private drawer: RadSideDrawer;
ngAfterViewInit() {
//fairly certain this statement is never entered
this.drawer = this.drawerComponent.sideDrawer;
this._changeDetectionRef.detectChanges();
}
ngOnInit() {
}
public openDrawer() {
console.log("Drawer method reached");
console.log(this.drawer); //returns undefined
this.drawer.showDrawer();
}
public onCloseDrawerTap() {
this.drawer.closeDrawer();
}
enableListMode()
{
this.router.navigate(["resList"])
}
}
例外:
JS:Angular正在开发模式下运行。调用enableProdMode() 启用生产模式。 System.err的: java.lang.NullPointerException:尝试调用虚方法&#39; void android.widget.FrameLayout.setVisibility(INT)&#39;在null对象上 参考System.err:at com.telerik.android.primitives.widget.sidedrawer.RadSideDrawer.handleOnDown(RadSideDrawer.java:452) System.err:at com.telerik.android.primitives.widget.sidedrawer.RadSideDrawer.onGesture(RadSideDrawer.java:430) System.err:at com.telerik.android.primitives.widget.sidedrawer.RadSideDrawer.onInterceptTouchEvent(RadSideDrawer.java:420) System.err:at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108) System.err:at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) System.err:at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) System.err:at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) System.err:at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) System.err:at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) System.err:at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) System.err:at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) System.err:at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) System.err:at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) System.err:at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197) System.err:at com.android.internal.policy.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:2403) System.err:at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737) System.err:at android.app.Activity.dispatchTouchEvent(Activity.java:2812) System.err:at com.android.internal.policy.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:2364) System.err:at android.view.View.dispatchPointerEvent(View.java:9520)System.err:
在 android.view.ViewRootImpl $ ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4242) System.err:at android.view.ViewRootImpl $ ViewPostImeInputStage.onProcess(ViewRootImpl.java:4095) System.err:at android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:3641) System.err:at android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:3694) System.err:at android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:3660) System.err:at android.view.ViewRootImpl $ AsyncInputStage.forward(ViewRootImpl.java:3786) System.err:at android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:3668) System.err:at android.view.ViewRootImpl $ AsyncInputStage.apply(ViewRootImpl.java:3843) System.err:at android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:3641) System.err:at android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:3694) System.err:at android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:3660) System.err:at android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:3668) System.err:at android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:3641) System.err:at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5938) System.err:at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5912) System.err:at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5873) System.err:at android.view.ViewRootImpl $ WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6041) System.err:at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) System.err:在android.os.MessageQueue.nativePollOnce(Native 方法)System.err:at android.os.MessageQueue.next(MessageQueue.java:323)System.err:at android.os.Looper.loop(Looper.java:135)System.err:at android.app.ActivityThread.main(ActivityThread.java:5480)System.err: at java.lang.reflect.Method.invoke(Native Method)System.err:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) System.err:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) ActivityManager:进程org.nativescript.rest(pid 1096)已经死亡 ActivityManager:cleanUpApplicationRecord - 1096