i have implemented a custom adapter on a fragment but it produces the error in the getView method of the fragment on the below line ,
CustomAdapter adapter = new CustomAdapter(this.getContext(), sub);
listView.setAdapter(adapter);
Here is the fragment_third.xml
<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"
tools:context=".ThirdFragment">
<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listviewthird"/></RelativeLayout>
Here is the sec.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
    android:id="@+id/image_below"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:src="@drawable/background_1" />
<TextView
    android:id="@+id/dept_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:text="@string/app_name"
    android:textSize="@dimen/text_size"
    android:textStyle="bold" /></RelativeLayout>
Here is the ThirdFragment.class
public class ThirdFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
String[] sub = {"random1", "random2", "random3", };
//code has been vomited.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_third, container, true);
    ListView listView = view.findViewById(R.id.listviewthird);
    CustomAdapter adapter = new CustomAdapter(this.getContext(), sub);
    listView.setAdapter(adapter);
    return view;
}
Here is the CustomAdapter class
public  class CustomAdapter extends ArrayAdapter<String> {
String[] example;
Context mContext;
public CustomAdapter(@NonNull Context context, String[] example) {
    super(context, R.layout.sec);
    this.example = example;
    this.mContext = context;
}
@Override
public int getCount() {
    return example.length;   //returns the size of the list
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    ViewHolder mViewHolder = new ViewHolder();
    if(convertView == null) {
        LayoutInflater mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflator.inflate(R.layout.sec, parent, false);
        mViewHolder.mExample = (TextView) convertView.findViewById(R.id.dept_name);
        mViewHolder.mExample.setText(subjects[position]);
        convertView.setTag(mViewHolder);
    }else {
        mViewHolder = (ViewHolder) convertView.getTag();
    }
    return convertView;
}
static class ViewHolder {
    TextView mExample;
}}
Am i doing wrong while implementing adapter on fragment? Someone explain me.
 
    