0

I am unable to get value of CoordinatorLayout in my Activity. When i try to get value by findviewbyid() it return null.

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/coordinatorLayoutLogin"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/login_bg">


    </android.support.design.widget.CoordinatorLayout>

Java:

private CoordinatorLayout coordinatorLayout;

protected void onCreate(Bundle savedInstanceState) {


        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayoutLogin);
    }

I am unable to understand why it is not working. Help me out.

I am using Samsung Note 8 with Android 9(One UI) installed also tried it on Samsung S8 and the behavior is same.

ADM
  • 20,406
  • 11
  • 52
  • 83
Mohsin
  • 902
  • 3
  • 23
  • 49
  • 1
    You just forgot to do **`setContentView(R.layout.activity_home);`** – AskNilesh Apr 29 '19 at 08:32
  • 1
    Can you please confirm if your findViewById call is after `setContentView(R.layout.your_activity_xml);` I just don't see it in the snippet that you have provided here – k1slay Apr 29 '19 at 08:32
  • @NileshRathod, k1slay thanks this is the problem i am trying to get get id before setting layout. – Mohsin Apr 29 '19 at 08:36
  • I am wondering too .. How will `private CoordinatorLayout coordinatorLayout` as local variable will compile ? – ADM Apr 29 '19 at 08:36
  • Oops error in copying @ADM – Mohsin Apr 29 '19 at 08:38

0 Answers0