title: Cannot add a null child view to a ViewGroup, though a value is given to the 'child view'
body: <p>My app crashes instantly when I launch it. For some reason, it states its an IllegalArgumentException though I can't understand why. I had instantiated the setContentView correctly. I tried to have the parameter as activity_main only with out the R.id, though i havent got any where, and ive looked a while on stackoverflow.</p>
  
  <p>ERROR:</p>
  
  <pre><code>06-14 17:00:44.262 6209-6209/com.example.jarvis_main.chatapptest E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.example.jarvis_main.chatapptest, PID: 6209
                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jarvis_main.chatapptest/com.example.jarvis_main.chatapptest.MainActivity}: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                     at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                     at android.os.Looper.loop(Looper.java:164)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                                  Caused by: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
                                                                                     at android.view.ViewGroup.addView(ViewGroup.java:4647)
                                                                                     at android.view.ViewGroup.addView(ViewGroup.java:4629)
                                                                                     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:283)
                                                                                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:145)
                                                                                     at com.example.jarvis_main.chatapptest.MainActivity.onCreate(MainActivity.java:40)
                                                                                     at android.app.Activity.performCreate(Activity.java:6980)
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                                     at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                                     at android.os.Looper.loop(Looper.java:164) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:6540) 
                                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                                     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>package com.example.jarvis_main.chatapptest;
  
  import android.content.Intent;
  import android.text.format.DateFormat;
  import android.support.annotation.NonNull;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.RelativeLayout;
  import android.widget.TextView;
  
  
  import com.firebase.ui.auth.AuthUI;
  import com.firebase.ui.database.FirebaseListAdapter;
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.database.FirebaseDatabase;
  
  import static com.example.jarvis_main.chatapptest.R.layout.activity_main;
  
  public class MainActivity extends AppCompatActivity {
  
  private static int SignInRequestCode = 1;
  private FirebaseListAdapter&lt;ChatMessage&gt; adapter;
  RelativeLayout activity_main;
  FloatingActionButton fab;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      activity_main = (RelativeLayout)findViewById(R.id.activity_main);
  
      setContentView(R.layout.activity_main);
      fab = (FloatingActionButton)findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              EditText input = (EditText)findViewById(R.id.input);
              FirebaseDatabase.getInstance().getReference().push().setValue(new ChatMessage(input.getText().toString(), FirebaseAuth.getInstance().getCurrentUser().getEmail()));
              input.setText("");
          }
      });
  
      if(FirebaseAuth.getInstance().getCurrentUser() == null)
      {
          startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(),SignInRequestCode);
      }
      else
      {
          Snackbar.make(activity_main, "Welcome "+FirebaseAuth.getInstance().getCurrentUser().getEmail(), Snackbar.LENGTH_SHORT).show();
          //Load content
          displayChatMessage();
      }
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      if(item.getItemId() == R.id.menu_sign_out){
          AuthUI.getInstance().signOut(this).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;(){
             @Override
                     public void onComplete(@NonNull Task&lt;Void&gt; Task){
                      Snackbar.make(activity_main,"Successfully signed out. Bye!", Snackbar.LENGTH_SHORT).show();
                      finish();
              }
          });
      }
      return true;
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main_menu,menu);
  
      return true;
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(requestCode == SignInRequestCode)
      {
          if(resultCode == RESULT_OK)
          {
              Snackbar.make(activity_main,"Successfully signed in. Welcome!", Snackbar.LENGTH_SHORT).show();
              displayChatMessage();
          }
          else{
              Snackbar.make(activity_main,"We couldn't sign you in.Please try again later", Snackbar.LENGTH_SHORT).show();
              finish();
          }
      }
  }
  
  private void displayChatMessage(){
      ListView listOfMsg = (ListView)findViewById(R.id.list_of_message);
      adapter = new FirebaseListAdapter&lt;ChatMessage&gt;(this, ChatMessage.class,R.layout.list_item,FirebaseDatabase.getInstance().getReference()) {
          @Override
          protected void populateView(View v, ChatMessage model, int position) {
              TextView messageText,messageUser,messageTime;
              messageText = (TextView) findViewById(R.id.message_text);
              messageUser = (TextView) findViewById(R.id.message_user);
              messageTime = (TextView) findViewById(R.id.message_time);
  
              messageText.setText(model.getMessageTexts());
              messageUser.setText(model.getMessageUsers());
              messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)", model.getMessageTime()));
  
          }
      };
      listOfMsg.setAdapter(adapter);
  }
  
  
  }
  </code></pre>