title: Getting Android Fragment no view found for ID
body: <p>First of, I've checked this question has been done and have tested the solutions that are explained on this site (although I may have committed errors in doing them as there are so many possible causes for the error).</p>
  <p>I mean solutions like the ones offered here:</p>
  <p><a href="https://stackoverflow.com/questions/7508044/android-fragment-no-view-found-for-id">Android Fragment no view found for ID?</a></p>
  <p>And here:</p>
  <p><a href="https://stackoverflow.com/questions/22761814/android-fragment-no-view-found-for-id-0x7f040034">Android Fragment : No view found for id 0x7f040034</a></p>
  <p>So, I'm explaining my particular case.</p>
  <p>First of, I'm setting the layout like this in my fragment:</p>
  <pre><code> public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          root = inflater.inflate(R.layout.activity_calendario_laboral, container, false);
          return root;
      }
  </code></pre>
  <p>That layout is, summarized, as it follows:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:id=&quot;@+id/main_content&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot;
      android:id=&quot;@+id/principal&quot;&gt;
  [...]
  &lt;/LinearLayout&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  <p>Once the view has been created I get to call this method:</p>
  <pre><code>final Fragment thisFragment=this;
  KotlinClass.Companion.setCalendarViewdateListener(calendarView,thisFragment,R.id.principal);
  </code></pre>
  <p>In that method of KotlinClass I get to call this function:</p>
  <pre><code>setFragment(FichajesFragment(), fragment,&quot;Fichajes&quot;,id);
  </code></pre>
  <p>Being the parameter fragment the thisFragment passed to setCalendarViewdateListener function.</p>
  <p>I've finally defined setFragment like this:</p>
  <pre><code>private fun setFragment(fragment: Fragment, fragment2: Fragment, tag: String, id: Int) {
                      val fragmentManager: FragmentManager = fragment2.activity!!.getSupportFragmentManager();
   val fragmentTransaction = fragmentManager.beginTransaction()
   for (activeFragment in fragmentManager.fragments) {
            fragmentTransaction.remove(activeFragment)
   }
   fragmentTransaction.add(id, fragment, tag)
   fragmentTransaction.commit()
   fragmentManager.executePendingTransactions()
   
  }
  </code></pre>
  <p>It raises an exception when executing fragmentManager.executePendingTransactions() telling that no view found for id, refering to the principal id of the linearlayout.</p>
  <p>What am I missing?</p>