This is xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
</LinearLayout>
This is Java code:
View mainLayout = findViewById(R.id.mainLayout);
// Or: LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainLayout);
Log.d("LAYOUT", mainLayout == null ? "NULL" : "NOT NULL"); // Always prints null
The layout is always null.
Why is that? The id is correct, all other elements can be fetched without any problems.
have you already attached it to the activity by using following code?