Question

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>
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top