title: How to display ArrayList Objects in GridView in Android in fragment
body: <p>I am trying to learn how to display a gridview with 3 columns in a fragment.  The values are from the strings.xml file as an array list.  When I run the application it crashes.  Can anyone help me to display the values in 3 columns namely Places, Description and Time.  I can`t proceed on how to display the read values in the gridview.</p>
  
  <pre><code>My Code are as follows:
  **Strings.XML**
      &lt;string-array name="PlacesName"&gt;
          &lt;item&gt;Durban&lt;/item&gt;
          &lt;item&gt;Paris&lt;/item&gt;
          &lt;item&gt;HongKong&lt;/item&gt;
          &lt;item&gt;Canada&lt;/item&gt;
      &lt;/string-array&gt;
  
      &lt;string-array name="Description"&gt;
          &lt;item&gt;Description1&lt;/item&gt;
          &lt;item&gt;Description2&lt;/item&gt;
          &lt;item&gt;Description3&lt;/item&gt;
      &lt;/string-array&gt;
  
      &lt;string-array name="ScheduleDate"&gt;
          &lt;item&gt;12/1/2015&lt;/item&gt;
          &lt;item&gt;13/2/2015&lt;/item&gt;
          &lt;item&gt;14/4/2015&lt;/item&gt;
          &lt;item&gt;15/5/2015&lt;/item&gt;
      &lt;/string-array&gt;
  
  **Fragment**
  
      */
  public class FlightFragment extends Fragment {
  
      GridView grid;
  
      public FlightFragment() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_flight, container, false);
          // Inflate the layout for this fragment
          grid = (GridView) view.findViewById(R.id.gridView);
          MyAdapter myAdapter = new MyAdapter();
          grid.setAdapter(myAdapter);
          return view;
  
      }
  
      class MyAdapter extends BaseAdapter {
  
          ArrayList&lt;Schedule&gt; list;
          private Context context;
  
          MyAdapter() {
              list = new ArrayList();
              Resources resources = context.getResources();
              String[] tempPlaces = resources.getStringArray(R.array.PlacesName);
              String[] tempDate = resources.getStringArray(R.array.ScheduleDate);
              String[] tempDescription = resources.getStringArray(R.array.Description);
              for(int count=0;count&lt;4;count++ ){
                  Schedule tempSchedule = new Schedule(tempPlaces[count],tempDate[count],tempDescription[count]);
                  list.add(tempSchedule);
              }
          }
          @Override
          public int getCount() {
              return list.size();
          }
  
          @Override
          public Object getItem(int position) {
              return list.get(position);
          }
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              Schedule tempSchedule = list.get(position);
              TextView textView;
              if (convertView == null){
                  textView = new TextView(context);
                  textView.setLayoutParams(new GridView.LayoutParams(85, 85));
                  textView.setPadding(8, 8, 8, 8);
              }
              else{
                  textView = (TextView) convertView;
              }
              textView.setText(tempSchedule.Place);
              return textView;
          }
      }
  
      class Schedule {
          String Place;
          String ScheduleTime;
          String Description;
  
          Schedule(String place, String scheduleTime, String description ) {
              this.Description = description;
              this.Place = place;
              this.ScheduleTime = scheduleTime;
          }
      }
  }
  </code></pre>
  
  <p>Error</p>
  
  <blockquote>
    <p>FATAL EXCEPTION: main
        java.lang.NullPointerException
                at com.ts.FlightFragment$MyAdapter.(FlightFragment.java:51)
                at com.ts.FlightFragment.onCreateView(FlightFragment.java:38)
                at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
                at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
                at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
                at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
                at android.os.Handler.handleCallback(Handler.java:725)
                at android.os.Handler.dispatchMessage(Handler.java:92)
                at android.os.Looper.loop(Looper.java:176)
                at android.app.ActivityThread.main(ActivityThread.java:5279)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>