I have implemented the fragment in android.
Now we try to send the data from activity to the fragment. But while sending the data we are getting the NullPointerException in *onCreateView*
method of fragment.
Following code of Activity.
setContentView(R.layout.fragment_1);
FragmentManager fm = getFragmentManager();
FragmentTranstction ft = fm.beginTransaction();
Fragment1 f1 = new Fragment1();
String text1 = "prakash";
Bundle bundle = new Bundle();
bundle.putString("sessionName", text1);
f1.setArguments(bundle);
ft.add(R.id.frag1, f1);
ft.commit();
Following code of Fragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String strtext = this.getArguments().getString("sessionName");
TextView sessionTitle = (TextView) getView()
.findViewById(R.id.session1);
sessionTitle.setText(strtext);
return inflater.inflate(R.layout.fragment_1, container, false);
}
what is the mistake i did, because of that i am getting NullPointerException, please help