title: View not attached to Window Manager
body: <pre><code>    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      LayoutInflater inflater = getLayoutInflater();
      LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.main, (ViewGroup) findViewById(R.id.root));
  
      Toast toast = new Toast(getApplicationContext());
      toast.setView(layout);
      toast.setDuration(2000);
      toast.show();
  }
  </code></pre>
  
  <p>This code throws an java.lang.IllegalArgumentException: View not attached to window manager.
  If i change the line</p>
  
  <pre><code>LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.main, (ViewGroup) findViewById(R.id.root));
  </code></pre>
  
  <p>to</p>
  
  <pre><code>LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.main, null);
  </code></pre>
  
  <p>works just fine. </p>
  
  <p>Can someone explain me why this happening? I'm new to Android platform and i'm just trying to understand how views and windows manager works. 
  Don't understand why if the root view was attached to Activity cannot be used anymore to a toast view.</p>
  
  <p>Any help is appreciated! </p>
  
  <p>Thanks!</p>