I am demo about communicate in two fragments in the parent activity. This is my code 

WebListFragment

```
public class WebListFragment extends Fragment implements AdapterView.OnItemClickListener {

    private List<String> list = new ArrayList<String>();
    private ListView listView;
    private ArrayAdapter<String> adapter;
    ListItemListener itemListener;

    public interface ListItemListener{
        void itemClick(String url);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        itemListener = (ListItemListener) activity;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.web_list_fragment, container, false);

        listView = (ListView) view.findViewById(R.id.listWeb);
        list.add("https://www.youtube.com/");
        list.add("http://news.zing.vn/");
        list.add("http://hdonline.vn/");

        adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(this);

        return view;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        itemListener.itemClick(list.get(position));
    }

} 

```

WebContentFragment

```
public class WebContentFragment extends Fragment{
    WebView webView;
    View view ;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = (LinearLayout)inflater.inflate(R.layout.web_content_fragment, container, false);
         webView = (WebView) this.getView().findViewById(R.id.webView);
        return view;
    }

    public void setUrl(String url, Context context){

        webView.loadUrl(url);
        Log.d("FF", "ABC");
    }

}

```

WebFragmentActivity

```
public class WebFragmentActivity extends AppCompatActivity implements WebListFragment.ListItemListener{

    private Fragment fragmentWebList;
    private Fragment fragmentWebContent;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_fragment);

    }

    @Override
    public void itemClick(String url) {
        WebContentFragment fragment = new WebContentFragment();
        fragment.setUrl(url,this);
    }
}

```

The problem which i have that when call method **setUrl** in **WebContentFragment** causes null pointer exception in LogCat. when i debug in this method **i saw view and webView equal null** although i assigned them **onCreateView**. I don't know why happened that. Can you show me the reason causes and the solution for this problem. Thanks 

My logcat:

```
java.lang.NullPointerException
            at com.nguyen.fragment.WebFragment.WebContentFragment.setUrl(WebContentFragment.java:61)
            at com.nguyen.fragment.WebFragment.WebFragmentActivity.itemClick(WebFragmentActivity.java:24)
            at com.nguyen.fragment.WebFragment.WebListFragment.onItemClick(WebListFragment.java:55)
            at android.widget.AdapterView.performItemClick(AdapterView.java:298)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
            at android.widget.AbsListView$1.run(AbsListView.java:3529)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

```