我有一个非常奇怪的例外!首先我引用一个相对布局,然后我尝试获取它的可见性状态,但是活动崩溃并在getVisibilty()处抛出NullPointerException;我不知道为什么!,我花了很多时间试图找出问题,但我不能!,这是我的活动代码:
setContentView(R.layout.main3d_activity);
RelativeLayout optionLayout;
optionLayout = (RelativeLayout) findViewById(R.id.main_optionLayout);
int vis= optionLayout.getVisibility();
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>
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" />
我尝试清理项目,重建工作区,甚至使用不同的模拟器,但同样的问题仍然存在!