title: how to fill custom list in Fragment in android?
body: <p>I have fragment i want to create a custom list view in it but when i send the parameters to adapter it's giving me error.</p>
  
  <p>This is my code in Fragment..</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.fragment_list, container, false);
  
      TextView tv = (TextView) v.findViewById(R.id.textView1);
  
      CustomAdapter arrayAdapter = new CustomAdapter(getActivity(), R.layout.search_catagory_list, prgmImages, prgmNameList);
      lv = (ListView) v.findViewById(R.id.listView);
  
      lv.setAdapter(arrayAdapter);
      return v;
  }
  </code></pre>
  
  <p>this is my MainHome.java</p>
  
  <pre><code>package com.example.yasee.bitescene.Fragments;
  
  import android.content.Context;
  import android.net.Uri;
  import android.os.Bundle;
  import android.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import com.example.yasee.bitescene.R;
  import com.example.yasee.bitescene.adapter.CustomAdapter;
  
  import java.util.ArrayList;
  
  public class MainHome extends Fragment {
      private static final String ARG_PARAM1 = "param1";
      private static final String ARG_PARAM2 = "param2";
      private String mParam1;
      private String mParam2;
  
  ListView lv;
  public static int [] prgmImages={R.drawable.one,R.drawable.two,R.drawable.three,R.drawable.four,R.drawable.five};
  public static String [] prgmNameList={"TRULY RANDOM","TEX MEX","BBQ","BRUNCH","SUSHI"};
  
  private OnFragmentInteractionListener mListener;
  
  public MainHome() {
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View v = inflater.inflate(R.layout.fragment_list, container, false);
  
      TextView tv = (TextView) v.findViewById(R.id.textView1);
  
      CustomAdapter arrayAdapter = new CustomAdapter(getActivity(), R.layout.search_catagory_list, prgmImages, prgmNameList);
      lv = (ListView) v.findViewById(R.id.listView);
  
      lv.setAdapter(arrayAdapter);
      return v;
  }
  
  public static MainHome newInstance(String param1, String param2) {
      MainHome fragment = new MainHome();
      Bundle args = new Bundle();
      args.putString(ARG_PARAM1, param1);
      args.putString(ARG_PARAM2, param2);
      fragment.setArguments(args);
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      if (getArguments() != null) {
          mParam1 = getArguments().getString(ARG_PARAM1);
          mParam2 = getArguments().getString(ARG_PARAM2);
      }
  }
  
  
  public void onButtonPressed(Uri uri) {
      if (mListener != null) {
          mListener.onFragmentInteraction(uri);
      }
  }
  
  @Override
  public void onAttach(Context context) {
      super.onAttach(context);
      if (context instanceof OnFragmentInteractionListener) {
          mListener = (OnFragmentInteractionListener) context;
      } else {
          throw new RuntimeException(context.toString()
                  + " must implement OnFragmentInteractionListener");
      }
  }
  
  @Override
  public void onDetach() {
      super.onDetach();
      mListener = null;
  }
  
  /**
   * This interface must be implemented by activities that contain this
   * fragment to allow an interaction in this fragment to be communicated
   * to the activity and potentially other fragments contained in that
   * activity.
   * &lt;p&gt;
   * See the Android Training lesson &lt;a href=
   * "http://developer.android.com/training/basics/fragments/communicating.html"
   * &gt;Communicating with Other Fragments&lt;/a&gt; for more information.
   */
  public interface OnFragmentInteractionListener {
      // TODO: Update argument type and name
      void onFragmentInteraction(Uri uri);
  }
  }
  </code></pre>
  
  <p>it show error like this..</p>
  
  <p><a href="https://i.stack.imgur.com/qWXwX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qWXwX.png" alt="enter image description here"></a></p>
  
  <p>this is my adapter code...</p>
  
  <pre><code>package com.example.yasee.bitescene.adapter;
  
  
  
  import android.app.Activity;
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.example.yasee.bitescene.Fragments.MainHome;
  import com.example.yasee.bitescene.R;
  import com.example.yasee.bitescene.Search;
  
  import java.util.ArrayList;
  
  public class CustomAdapter extends BaseAdapter {
      String [] result;
      Context context;
      int [] imageId;
      private static LayoutInflater inflater=null;
  
  public CustomAdapter(Activity activity, int search_catagory_list, int[] prgmImages, String[] prgmNameList) {
      // TODO Auto-generated constructor stub
      result=prgmNameList;
      context=activity;
      imageId=prgmImages;
      inflater = ( LayoutInflater )context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return result.length;
  }
  
  @Override
  public Object getItem(int position) {
      // TODO Auto-generated method stub
      return position;
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return position;
  }
  
  public class Holder
  {
      TextView tv;
      ImageView img;
  }
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      Holder holder=new Holder();
      View rowView;
      rowView = inflater.inflate(R.layout.search_catagory_list, null);
      holder.tv= (TextView) rowView.findViewById(R.id.textView1);
      holder.img=(ImageView) rowView.findViewById(R.id.imageView1);
      holder.tv.setText(result[position]);
      holder.img.setImageResource(imageId[position]);
      rowView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
          }
      });
      return rowView;
  }
  
  }
  </code></pre>
  
  <p>my error is...</p>
  
  <blockquote>
    <p>06-13 07:31:00.399 3569-3569/com.example.yasee.bitescene E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.yasee.bitescene, PID: 3569
                                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yasee.bitescene/com.example.yasee.bitescene.Search}: java.lang.NullPointerException
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
                                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:136)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5017)
                                                                                   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)
                                                                                Caused by: java.lang.NullPointerException
                                                                                   at com.example.yasee.bitescene.Fragments.MainHome.onCreateView(MainHome.java:44)
                                                                                   at android.app.Fragment.performCreateView(Fragment.java:1700)
                                                                                   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
                                                                                   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
                                                                                   at android.app.BackStackRecord.run(BackStackRecord.java:684)
                                                                                   at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
                                                                                   at android.app.Activity.performStart(Activity.java:5240)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:136) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5017) 
                                                                                   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) </p>
  </blockquote>