ClassCastException: android.support.v4.widget.SwipeRefreshLayout cannot be cast to android.widget.ListView
<p>sometimes my app get a crash. I dont no why it doesent work sometimes, i didnt change anything. In my fragment i add 2 items on <strong>onViewCreated()</strong></p>

<pre><code>listview_products = (ListView) view.findViewById(R.id.listview_product_list);
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.productlist_swipe_refresh);
</code></pre>

<p>The error is this near (it's line 60)<strong>listview_products = (ListView) view.findViewById(R.id.listview_product_list);</strong></p>

<p>This is my layout file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"&gt;

&lt;android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/productlist_swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;
    &lt;ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listview_product_list"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" /&gt;
&lt;/android.support.v4.widget.SwipeRefreshLayout&gt;
</code></pre>

<p></p>

<p>Why i get the error? What can i do to fix it?</p>

<blockquote>
  <p>01-31 14:50:09.583 22103-22103/de.app.me.de E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: de.app.me.de, PID: 22103
                                                                        java.lang.RuntimeException: Unable to start activity ComponentInfo{de.app.me.de/de.app.me.de.account_overview}: java.lang.ClassCastException: android.support.v4.widget.SwipeRefreshLayout cannot be cast to android.widget.ListView
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
                                                                            at android.app.ActivityThread.access$900(ActivityThread.java:172)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:145)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5832)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                                         Caused by: java.lang.ClassCastException: android.support.v4.widget.SwipeRefreshLayout cannot be cast to android.widget.ListView
                                                                            <strong>at de.app.me.de.FragmentProductList.onViewCreated(FragmentProductList.java:60)</strong>
                                                                            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:918)
                                                                            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
                                                                            at android.app.BackStackRecord.run(BackStackRecord.java:833)
                                                                            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
                                                                            at android.app.Activity.performStart(Activity.java:6257)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2621)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
                                                                            at android.app.ActivityThread.access$900(ActivityThread.java:172) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                            at android.os.Looper.loop(Looper.java:145) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5832) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) </p>
</blockquote>

<p>Thanks for help!</p>

<p>EDIT:</p>

<pre><code>package de.app.me.de;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.ClipData;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import org.json.simple.ItemList;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import api.Request;
import classes.app.me.de.ListViewCustomAdapter;
import classes.app.me.de.ListViewItem;

/**
 * Created by ME on 15.01.2016.
 */
public class FragmentProductList extends Fragment{

    public FragmentProductList() {}
    private Context context;
    private TextView textView;
    private View rootView;
    private Request r;
    public ArrayList&lt;ListViewItem&gt; arrayList = new ArrayList&lt;ListViewItem&gt;();
    private ListView listview_products;
    SwipeRefreshLayout mSwipeRefreshLayout;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        this.rootView = inflater.inflate(R.layout.fragment_productlist, container, false);
        this.context = rootView.getContext();


        return this.rootView;
    }


    @Override
    public void onViewCreated(View view, Bundle saBundle) {
        getActivity().setTitle(R.string.title_activity_account_plist);

        listview_products = (ListView) view.findViewById(R.id.listview_product_list);
        mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.productlist_swipe_refresh);

        listview_products.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {

                Bundle bundle = new Bundle();

                bundle.putInt("pid", arrayList.get(position).getId());

                Fragment f = new FragmentProductManager();
                f.setArguments(bundle);

                FragmentManager fm = getFragmentManager();
                fm.beginTransaction().replace(R.id.frame_container, f).commit();

            }
        });


        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                Update();

            }
        });

        Update();
    }

    public void Update () {

        arrayList.clear();

        new GetProductList().execute();
        mSwipeRefreshLayout.setRefreshing(false);

    }

    public void UpdateList (ArrayList list) {

        ListViewCustomAdapter adapter = new ListViewCustomAdapter(rootView.getContext(), list);

        listview_products.setAdapter(adapter);


    }

    private class GetProductList extends AsyncTask&lt;String, Void, Boolean&gt; {

        private ProgressDialog pd;

        private android.app.AlertDialog.Builder dlgAlert;
        @Override
        protected Boolean doInBackground(String... params) {

            ...

        }

        @Override
        protected void onPreExecute() {

            ...

        }

        @Override
        protected void onPostExecute(Boolean status) {

        ...

        }
    }

}
</code></pre>