0

So im trying to get a View by findViewById(). It works like a charm on emulator 4.0 and 41. and on a android 2.3 smartphone but when trying it on a samsung galaxy tab - the variable is always null.

HomeActivity.java

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.start_new_user);
    ViewFlipper vf = (ViewFlipper) findViewById(R.id.viewFlipper1_newuser);

vf is always null on galaxy-tab. if i try to do something with it like vf.getContext() ill get a NPE.

start_new_user.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tV_new_user"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp"
        android:background="@drawable/roundedcorner"
        android:padding="15dp"
        android:text="@string/start_new_user" />


  <LinearLayout
      android:id="@+id/rl_calendar_newuser"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:orientation="vertical" >

        {...}
    </LinearLayout>




    <ViewFlipper
        android:id="@+id/viewFlipper1_newuser"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </ViewFlipper>

</LinearLayout>
</LinearLayout>
Yalla T.
  • 3,707
  • 3
  • 23
  • 36
  • 2
    do you have several versions of the layout? in layout-xhdpi, or in layout-v14 or something? also, can you post the stacktrace? there may be something else – njzk2 Sep 10 '12 at 09:02

1 Answers1

1

check if that view is defined in all of layouts versions.

Bob
  • 22,810
  • 38
  • 143
  • 225
  • thanks, I forgot in an earlier version I made an extra layout version for landscape. So simple yet I wasnt able to figure it out alone in over an hour. Will accept your answer in 5 minutes when i can. – Yalla T. Sep 10 '12 at 09:09