title: Android - Listview in Fragment
body: <p>I want to create a ListView in Fragment but something goes wrong.
  In layout listmygroups.xml are three TextViews (trainermygroupslistwhen, trainermygroupslistwhere, trainermygroupslistname). 
  I try to open fragment with listview(TrainerMyGroups) from another fragment by:</p>
  
  <pre><code>getFragmentManager().beginTransaction().replace(R.id.MainContainer,new TrainerMyGroups()).addToBackStack(null).commit();
  </code></pre>
  
  <p>TrainerMyGroups.java:</p>
  
  <pre><code>package com.hgyghyfghyu.apkana40;
  
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ListView;
  
  
  /**
   * A simple {@link Fragment} subclass.
   */
  public class TrainerMyGroups extends Fragment {
  
  
      ListView listView;
      TrainerGroupsAdapter adapter;
      String when[]={"tak","ret","sd"};
      String where[]={"dsf","sdf","sdfsdf"};
      String name[]={"sdfsdf","xcvxcv","xcvxcv"};
  
      public TrainerMyGroups() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_trainer_my_groups, container, false);
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          listView = (ListView) getActivity().findViewById(R.id.trainermygroupslistview);
          adapter = new TrainerGroupsAdapter(getContext(),R.layout.list_mygroups);
  
          for(int i=0;i&lt;3;i++){
              TrainerGroupsDataProvider dataprovider = new TrainerGroupsDataProvider(when[i],name[i],where[i]);
              adapter.add(dataprovider);
  
          }
          listView.setAdapter(adapter);
      }
  }
  </code></pre>
  
  <p>TrainerGroupsAdapter.java:</p>
  
  <pre><code>package com.hgyghyfghyu.apkana40;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  
  import java.util.List;
  import java.util.ArrayList;
  
  /**
   * Created by dd on 2016-04-04.
   */
  public class TrainerGroupsAdapter extends ArrayAdapter {
  
      List list = new ArrayList();
  
      public TrainerGroupsAdapter(Context context, int resource) {
          super(context, resource);
      }
  
      static class Datahandler{
          TextView name;
          TextView when;
          TextView where;
      }
  
      @Override
      public void add(Object object) {
          super.add(object);
          list.add(object);
      }
  
      @Override
      public int getCount() {
          return this.list.size();
      }
  
      @Override
      public Object getItem(int position) {
          return this.list.get(position);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row;
          row=convertView;
          Datahandler handler;
          if(convertView==null){
              LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              row= inflater.inflate(R.layout.list_mygroups,parent,false);
              handler = new Datahandler();
              handler.name =  (TextView) row.findViewById(R.id.trainermygroupslistname);
              handler.where =  (TextView) row.findViewById(R.id.trainermygroupslistwhere);
              handler.when =  (TextView) row.findViewById(R.id.trainermygroupslistwhen);
              row.setTag(handler);
          }
          else {
              handler = (Datahandler)row.getTag();
          }
  
          TrainerGroupsDataProvider dataProvider;
          dataProvider = (TrainerGroupsDataProvider)this.getItem(position);
          handler.name.setText(dataProvider.getName());
          handler.when.setText(dataProvider.getWhen());
          handler.where.setText(dataProvider.getWhere());
          return row;
      }
  
  
  }
  </code></pre>
  
  <p>and there is error from AndroidMonitor</p>
  
  <pre><code>FATAL EXCEPTION: main
                                                                            Process: com.hgyghyfghyu.apkana40, PID: 27778
                                                                            java.lang.NullPointerException
                                                                                at com.hgyghyfghyu.apkana40.TrainerMyGroups.onCreate(TrainerMyGroups.java:41)
                                                                                at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
                                                                                at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                                                at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                                                                                at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
                                                                                at android.os.Handler.handleCallback(Handler.java:733)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:136)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5045)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                                                                                at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>line 41 from TrainerMyGroups is</p>
  
  <pre><code>listView.setAdapter(adapter);
  </code></pre>
  
  <p>I am not sure but probably this solution works only in Activity, not in Fragment, How can I change my code to make it workable?</p>
  
  <p>element list xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="5"&gt;
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
              &lt;TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/trainermygroupslistwhen"
                  android:textStyle="bold"
                  android:textSize="20sp"
                  android:textColor="#FFFFFF"
                  android:layout_centerInParent="true"/&gt;
          &lt;/RelativeLayout&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="3"&gt;
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
              &lt;TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/trainermygroupslistname"
                  android:textStyle="bold"
                  android:textSize="10sp"
                  android:textColor="#FFFFFF"
                  android:layout_centerInParent="true"/&gt;
          &lt;/RelativeLayout&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="3"&gt;
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
              &lt;TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/trainermygroupslistwhere"
                  android:textStyle="bold"
                  android:textSize="10sp"
                  android:textColor="#FFFFFF"
                  android:layout_centerInParent="true"/&gt;
          &lt;/RelativeLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>