Some problems with android listview <p>I am trying to make some practice about android <code>ListView</code>. Code bellow is in a<br> <code>listfragment</code>:</p> <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view= inflater.inflate(R.layout.frag_getfriends,container,false); friendsListView=(ListView)view.findViewById(android.R.id.list); infoTextView=(TextView)view.findViewById(android.R.id.empty); swipe=(SwipeRefreshLayout)view.findViewById(R.id.swipe_refresh); swipe.setOnRefreshListener(this); arrayAdapter=new DataListAdapter(getActivity(),R.layout.userinfo_list_config,null); friendsListView.setAdapter(arrayAdapter); friendsListView.setOnItemClickListener((parent,itemView,position,id)-&gt;{ if(friends!=null){ User friend=friends.get(position); Toast.makeText(getActivity(),friend.getName(),Toast.LENGTH_SHORT).show(); } }); presenter.startQuery(true); return view; } </code></pre> <p><code>Adapter</code> constructor is:</p> <pre><code> public DataListAdapter(Context context, int itemLayoutResoureId, ArrayList&lt;User&gt;friends){ super(context,itemLayoutResoureId,friends); this.context=context; this.users=new ArrayList&lt;&gt;(); users.addAll(friends); } </code></pre> <p>At the beginning,the <code>listview</code> has no data to display until this app fetches some data online:</p> <pre><code>@Override public void setDataList(ArrayList&lt;User&gt; friendsList) { this.friends=friendsList; arrayAdapter.clear(); arrayAdapter.addAll(friendsList); arrayAdapter.notifyDataSetChanged(); friendsListView.setAdapter(arrayAdapter); } </code></pre> <p>Later I can do some refresh.And each refresh happenes,the callback</p> <pre><code>setDataList </code></pre> <p>is fired and <code>listview</code> get updated. However,the app crashed. Logcat shows:</p> <pre><code> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mrdreamer.iknow/com.example.mrdreamer.iknow.Social.GetFriends}: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference at java.util.ArrayList.addAll(ArrayList.java:188) at com.example.mrdreamer.iknow.Social.DataListAdapter.&lt;init&gt;(DataListAdapter.java:35) at com.example.mrdreamer.iknow.Social.GetFriendsFrag.onCreateView(GetFriendsFrag.java:42) at android.app.Fragment.performCreateView(Fragment.java:2220) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148) at android.app.BackStackRecord.run(BackStackRecord.java:793) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535) at android.app.FragmentController.execPendingActions(FragmentController.java:325) at android.app.Activity.performStart(Activity.java:6252) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) </code></pre> <p>The problem is that in:</p> <pre><code>arrayAdapter=new DataListAdapter(getActivity(),R.layout.userinfo_list_config,null); </code></pre> <p>the last parameter cannot be null,which I understand. Now should I change to SimpleCursorAdapter or just make some change to current code? :) Thank you in advance.I am new to android developement.I am be very gratefull.:)</p>