Ahm*_*mad 2 android nullpointerexception android-layout
我有一个非常奇怪的例外!首先我引用相对布局,然后我尝试获取其可见性状态,但活动崩溃并在getVisibilty()时抛出NullPointerException ; 我不知道为什么!,我花了很多时间试图找出问题,但我不能!,这是我的活动代码:
setContentView(R.layout.main3d_activity);
RelativeLayout optionLayout;
optionLayout = (RelativeLayout) findViewById(R.id.main_optionLayout);
int vis= optionLayout.getVisibility();
Run Code Online (Sandbox Code Playgroud)
main3d_activity代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include
android:id="@+id/include_headerbar"
android:layout_width="fill_parent"
android:layout_height="60dp"
layout="@layout/headerbar_layout" />
<include
android:id="@+id/include_footerbar"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
layout="@layout/footerbar_layout" />
<ViewFlipper
android:id="@+id/vf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/include_footerbar"
android:layout_below="@+id/include_headerbar" >
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/container_mainlayout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/living_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/bedroom_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/childrenbedroom_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/kitchen_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/dinningroom_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/corridor_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/roof_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/garden_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/garage_layout" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/container_mainlayout" />
</ViewFlipper>
<include
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_above="@+id/include_footerbar"
android:layout_alignParentRight="true"
android:layout_below="@+id/include_headerbar"
layout="@layout/slidingdrawer_infolayout" />
<include
android:layout_width="300dp"
android:layout_height="400dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
layout="@layout/slidingdrawer_roomslistlayout" />
<include
android:layout_width="350dp"
android:layout_height="300dp"
android:layout_above="@+id/include_footerbar"
android:layout_alignParentRight="true"
layout="@layout/logger_layout" />
<include
android:id="@+id/include_relativeMenu"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/include_headerbar"
layout="@layout/options_menulayout" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
options_menuLayout xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_optionLayout"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/main_headerbackground"
android:orientation="vertical"
android:visibility="invisible" >
<Button
android:id="@+id/relativeMenuAllSensorsButton"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="@drawable/main_headerbackground"
android:gravity="center_vertical|center_horizontal"
android:text="Activation List"
android:textColor="@android:color/white"
android:textSize="18sp" />
<Button
android:id="@+id/relativeMenuUsersButton"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="@+id/relativeMenuAllSensorsButton"
android:background="@drawable/main_headerbackground"
android:gravity="center_vertical|center_horizontal"
android:text="Users"
android:textColor="@android:color/white"
android:textSize="18sp" />
<Button
android:id="@+id/relativeMenuPreferencesButton"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="@+id/relativeMenuUsersButton"
android:background="@drawable/main_headerbackground"
android:gravity="center_vertical|center_horizontal"
android:text="Settings"
android:textColor="@android:color/white"
android:textSize="18sp" />
Run Code Online (Sandbox Code Playgroud)
我尝试清理项目,重建工作区甚至使用不同的模拟器,但同样的问题仍然存在!
在main3d_activity.xml你有:
<include
android:id="@+id/include_relativeMenu"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/include_headerbar"
layout="@layout/options_menulayout" />
Run Code Online (Sandbox Code Playgroud)
然后在options_menulayout.xml你有:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_optionLayout"
Run Code Online (Sandbox Code Playgroud)
因此,当您包含id时,它看起来像是覆盖了id.去掉
android:id="@+id/include_relativeMenu"
Run Code Online (Sandbox Code Playgroud)
从包含,或搜索该ID而不是另一个.
| 归档时间: |
|
| 查看次数: |
3176 次 |
| 最近记录: |