I am having a very weird exception!. First I reference to a Relative layout, then i try to get its visibility state, but the activity crashes and throws a NullPointerException at getVisibilty();
I Have no idea why!, I spent a lot of time trying to figure out the problem but I couldn’t!,Here is my Activity code:
setContentView(R.layout.main3d_activity);
RelativeLayout optionLayout;
optionLayout = (RelativeLayout) findViewById(R.id.main_optionLayout);
int vis= optionLayout.getVisibility();
main3d_activity code:
<?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 code:
<?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" />
I tried cleaning the project, rebuilding the workspace and even using different emulator but the same problem persists!
In
main3d_activity.xmlyou have:And then in
options_menulayout.xmlyou have:So it looks like you’re overriding the id when you include it. Remove
from the include, or search for that ID rather than the other one.