title: java.lang.NullPointerException: Layout parameters cannot be null
body: <p>I've been working on making my own custom ImageView class on Android. I've read the documentation on layouts, fragments, activities and ImageView.</p>
  
  <p>I've looked at Stack posts on how to create an ImageView programatically but I've run into a snag I can't seem find a solution to (reading the top hits for searching the above error did not apply to my issue).</p>
  
  <p>I have an activity, and inside that activity I have a fragment. Inside the fragment I am creating an ImageView (its called iImage but its just an extended ImageView class).</p>
  
  <pre><code>@Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
      {
          // Inflate the layout for this fragment
          iImage image = new iImage(getActivity());
          image.setImageResource(R.drawable.name_splash);
          LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(1500,1100);
          image.setLayoutParams(par);
          container.addView(image);
          View rootView = inflater.inflate(R.layout.fragment_edit_photo, container, false);
          return rootView;
      }
  </code></pre>
  
  <p>However, when  I run the app, it loads, and it works just fine, however I get this error:</p>
  
  <pre><code> java.lang.RuntimeException: Unable to start activity ComponentInfo{co.name.app/co.name.app.CameraEditorActivity}: java.lang.NullPointerException: Layout parameters cannot be null
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
  </code></pre>
  
  <p>....</p>
  
  <pre><code> Caused by: java.lang.NullPointerException: Layout parameters cannot be null
          at android.view.View.setLayoutParams(View.java:11470)
          at co.name.app.EditPhotoFragment.onCreateView(EditPhotoFragment.java:89)
  </code></pre>
  
  <p>Can you advise what the underlying issue is?</p>