title: Trying to create dynamic textview from fragment.Getting null pointer exception error?
body: <p>I am created a Linear layout in java code and connected to the XML code so that it will add the required number of text views in the the layout.</p>
  
  <p>I tested it out by adding one textview gave assigned text, size etc. It was giving me.</p>
  
  <p>I just been pulling my hair out over this.</p>
  
  <pre><code>package com.example.user.navigationdrawer;
  
  import android.app.Fragment;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.select.Elements;
  
  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.Locale;
  
  public class FirstFragment extends Fragment {
  
      View myView;
      static final String url = "https://website.com";
      ArrayList&lt;String&gt; outPut = new ArrayList&lt;&gt;();
      LinearLayout diaryLayout = (LinearLayout) myView.getRootView().findViewById(R.id.connections); // compiler giving error here.
  
      //ArrayList&lt;String&gt; h4 = new ArrayList&lt;&gt;();
  
      @Nullable@Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          myView = inflater.inflate(R.layout.first_layout, container, false);
  
          new Ann().execute();
          return myView;
      }
  
      private class Ann extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected Void doInBackground(Void...params) {
              try {
  
                  // Connect to the web site
                  Document document = Jsoup.connect(url).get();
                  // Get the html document title
                  Elements notificationWall = document.select("div[class=flex_column av_one_fifth  flex_column_table_cell av-equal-height-column av-align-top av-zero-column-padding   " + "avia-builder-el-11  el_after_av_one_fifth  el_before_av_one_third]"); //Connect to website.The Notification wall.
  
                  Elements sectionTag = notificationWall.select("section"); //Get section tag.
                  Elements contentTitles = sectionTag.select("h4"); // Get H4
                  Elements bodyText = sectionTag.select("p"); //Get P
                  Elements linkTag = sectionTag.select("a"); //Get links
                  Elements images = sectionTag.select("img"); // get image.
  
                  for (int section = 0; section &lt; sectionTag.size(); section++) {
                      outPut.add(sectionTag.get(section).text());
                  }
  
              } catch(IOException e) {
                  e.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              // Set title into TextView
              //here.
              TextView dynamicTextView = new TextView(diaryLayout.getContext());
              dynamicTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
              dynamicTextView.setText("TEST");
              dynamicTextView.setTextSize(30);
  
              diaryLayout.addView(dynamicTextView);
  
          }
      }
  }
  </code></pre>