java.lang.IllegalArgumentException:无法将空子视图添加到ViewGroup Nativescript-Angular

时间:2019-01-17 16:54:52

标签: angular nativescript

我在我的NativeScript-Angular项目中添加了side drawer plugin。我的app.component.html如下:

<RadSideDrawer>
   <GridLayout tkDrawerContent rows="auto, *" class="sidedrawer sidedrawer-left">
      <StackLayout row="0" style="margin-bottom: 30px;">
         <StackLayout orientation="horizontal" style="padding: 13px 20px;">
            <label text="Hasan Tekin" textWrap="false" style="font-size: 20px;color: white;margin: 20 30 10 10;"></label>
         </StackLayout>
      </StackLayout>
      <ScrollView row="1">
         <StackLayout class="sidedrawer-content">
            <StackLayout *ngFor="let item of state.sideDrawer.items; let i = index">
               <StackLayout orientation="horizontal" style="padding: 13px 0;" (tap)="activateMenuItem(i)" [routerLink]="['/mysurveys']">
                  <Image [src]="item.active ? '~/assets/images/arrowGreen.png' : '~/assets/images/arrowGray.png'" style="width: 40px;margin: 0 20px;"></Image>
                  <label text={{item.text}} textWrap="false" [class]="item.active ? 'menuItemActive' : 'menuItem'"></label>
               </StackLayout>
               <StackLayout class="hr-dark m-10">
               </StackLayout>
            </StackLayout>
         </StackLayout>
      </ScrollView>
   </GridLayout>

   <page-router-outlet tkMainContent class="page page-content"></page-router-outlet>
</RadSideDrawer>

当我运行tns run android --bundle时,会出现此错误:

Error: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup

可能是什么原因?

1 个答案:

答案 0 :(得分:1)

这完全是我的错误。我在app.module.ts中而不是app.module.tns.ts中导入了边抽屉。现在,我删除了该导入并将其写入app.module.tns.ts,它可以正常工作。