在我的NativeScript Angular项目中,这是我的路由器模块:
export const routes = [
{path: "user", component: UserComponent,
children: [
{
path: "dashboard",
component: DashboardComponent
},
{
path: "notice",
component: NoticeComponent
},
{
path: "attendance",
component: AttendanceComponent
},
{
path: "subject",
component: SubjectComponent,
children: [
{
path: "discussion",
component: DiscussionComponent
},
{
path: "assignment",
component: AssignmentComponent,
children: [
{
path: "assignment-report", component: AssignmentReportComponent
}
]
}
]
}
]
}
];
user.component.html
的底部栏带有Dashboard,Notice和Attendance组件的链接,这些链接显示在UserComponent的路由器插座中。用户单击user/dashboard
路线中的主题以转到主题。 SubjectComponent再次在SubjectComponent内部的路由器插座中显示了两个“讨论”和“分配”选项卡。
问题::当我进入SubjectComponent并单击底部栏中的任何链接以导航至“仪表板”,“出勤”或“通知”时,应用程序崩溃,并且出现此错误:
“主”线程上发生未捕获的异常。 调用js方法onPause失败 错误:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int android.graphics.Bitmap.getWidth()'。
如果我只删除SubjectComponent中的<page-router-outlet>
,它将很好地工作。我知道我在嵌套这些路线时遇到了麻烦,但是错误并没有抛出任何具体的信息,所以我无法弄清楚。
操场样本:打开操场样本,然后单击“打开主题”按钮。当您在主题页面上时,单击底部的“仪表盘”按钮。您将得到错误。 游乐场链接:https://play.nativescript.org/?template=play-ng&id=qGvsVF&v=11
添加一些可能与此问题相关的代码段。
user.component.html
<GridLayout style="background-color: #ffffff;" rows="*, auto">
<StackLayout class="content-container" row="0">
<page-router-outlet></page-router-outlet>
</StackLayout>
<StackLayout class="bottom-bar" row="1">
<StackLayout class="menu-container" horizontalAlignment="center" orientation="horizontal">
<Image (tap)="openDashboard()" [ngStyle]="{'border-color': isHome?'#1d87c9' :'#ffffff'}" class="btn-home" [src]="menuImages[0]"></Image>
<Image (tap)="openNotice()" [ngClass]="{'btn-active': isNotice}" class="btn-icon" [src]="menuImages[1]"></Image>
<Image (tap)="openAttendance()" [ngClass]="{'btn-active': isAttendance}" class="btn-icon" [src]="menuImages[2]"></Image>
</StackLayout>
</StackLayout>
user.component.ts中的
openDashboard()方法。 openNotice()和openAttendance()相似
import { RouterExtensions } from "nativescript-angular/router";
constructor(private routerExtensions: RouterExtensions) {}
openDashboard(){
this.routerExtensions.navigateByUrl('user/dashboard');
this.menuImages = ["res://uni_full","res://notice_default","res://attendance_default"];
this.isHome = true;
this.isNotice = false;
this.isAttendance = false;
}
subject.component.html
<StackLayout class="main">
<GridLayout rows="auto, *">
<StackLayout row="0" class="subject-ribbon">
<StackLayout class="tab-container" orientation="horizontal">
<StackLayout (tap)="changeTab('discussion')" class="tab">
<Label class="tab-label" text=" Discussion"></Label>
<Label class="tab-indicator"></Label>
</StackLayout>
<StackLayout (tap)="changeTab('assignment')" class="tab">
<Label class="tab-label" text=" Assignment"></Label>
<Label class="tab-indicator"></Label>
</StackLayout>
</StackLayout>
</StackLayout>
<ScrollView (scroll)="onScroll($event)" row="1">
<StackLayout>
<page-router-outlet></page-router-outlet>
</StackLayout>
</ScrollView>
</GridLayout>
subject.component.ts
import { RouterExtensions } from "nativescript-angular/router";
constructor(private routerExtensions: RouterExtensions) {}
changeTab(tabName){
this.tabMode = tabName;
this.routerExtensions.navigateByUrl('user/subject/' + tabName);
}
答案 0 :(得分:1)
我怀疑问题是您使用ScrollView包裹了框架(页面路由器出口)。由于种种原因,这不是一个好习惯,并且该应用似乎因此崩溃了。在页面内移动ScrollView可解决此问题。