title: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference
body: <p>iam trying to create a movie app from api but first iam making some fake data to ensure that my adapter is working correctly so iam making my own adapter using gridview and some data in fragment i searched a lot but i could not to solve this on my own code,thanks in advance.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>    package besho.hallofmovies;
      import android.app.FragmentManager;
      import android.app.FragmentTransaction;
      import android.support.v7.app.AppCompatActivity;
      import android.os.Bundle;
  
      public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      MovieFragment movieFragment = new MovieFragment();
      FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction transaction = fragmentManager.beginTransaction();
      transaction.add(R.id.main_activity,movieFragment,"movieFragment");
      transaction.commit();
      }
  
      }
  </code></pre>
  
  <p>MovieFragment.java</p>
  
  <pre><code>    package besho.hallofmovies;
  
      import android.app.Fragment;
      import android.app.ListFragment;
      import android.content.Context;
      import android.content.res.Resources;
      import android.os.Bundle;
      import android.view.LayoutInflater;
      import android.view.Menu;
      import android.view.MenuInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.ArrayAdapter;
      import android.widget.BaseAdapter;
      import android.widget.GridView;
      import android.widget.ImageView;
      import java.lang.reflect.Array;
      import java.util.ArrayList;
  
  public class MovieFragment extends Fragment {
  
  GridView myGridView ;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setHasOptionsMenu(true);
  
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      inflater.inflate(R.menu.movie_fragment,menu);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.fragment_movie,container,false);
      myGridView = (GridView) getActivity().findViewById(R.id.gridView);
      myGridView.setAdapter(new MoviesAdapter(getActivity()));
  
      return view ;
  }
  }
  
  class Movie
  {
  String name;
  int movieID;
  
  Movie (String name, int movieID)
  {
      this.movieID=movieID;
      this.name=name;
  }
  }
  
  class MoviesAdapter extends BaseAdapter
  {
  ArrayList&lt;Movie&gt; movies;
  Context context;
  MoviesAdapter (Context c)
  {
      this.context=c;
      movies = new ArrayList&lt;Movie&gt;();
      Resources res = c.getResources();
      String[] moviesNames = res.getStringArray(R.array.values);
      int[] moviesImages = {R.drawable.pic_1,R.drawable.pic_2,R.drawable.pic_3,R.drawable.pic_4};
  
      for (int i=0;i&lt;moviesNames.length;i++)
      {
          Movie tempMovie = new Movie(moviesNames[i],moviesImages[i]);
          movies.add(tempMovie);
      }
  }
  
  @Override
  public int getCount() {
      return movies.size();
  }
  
  @Override
  public Object getItem(int position) {
      return movies.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  class ImageViewHolder
  {
      ImageView myImage;
      ImageViewHolder(View v)
      {
          myImage = (ImageView) v.findViewById(R.id.imageView);
      }
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      View item=convertView;
      ImageViewHolder myHolder;
      if (item == null)
      {
         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         item = inflater.inflate(R.layout.item_layout,parent,false);
         myHolder = new ImageViewHolder(item);
         item.setTag(myHolder);
      }
  
      else
      {
          myHolder = (ImageViewHolder) item.getTag();
      }
  
      Movie temp = movies.get(position);
      myHolder.myImage.setImageResource(temp.movieID);
      return item;
  }
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  tools:context="besho.hallofmovies.MainActivity"
  android:id="@+id/main_activity"&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>fragment_movie.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;GridView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/gridView"
      android:layout_gravity="left|top"
      android:numColumns="auto_fit"
      android:stretchMode="columnWidth"
      android:columnWidth="190dp"
      /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>item_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/movie_item_layout"&gt;
  
  &lt;ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"
      android:scaleType="centerCrop"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/8ZuIl.jpg" rel="nofollow">logcat.sceenshot</a></p>