I've been trying to send a string of data from my activity to a fragment using bundle but when I try to access it, it gives a nullpointerexception.
The oncreate method in the activity looks like this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chart);
// Setup toolbar and title
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
readDb();
printChart();
printTop10();
Bundle bundle = new Bundle();
bundle.putString("edttext", myString);
// set Fragmentclass Arguments
ToolbarFragment fragobj = new ToolbarFragment();
fragobj.setArguments(bundle);
}
and the fragment on the onCreateView looks like this
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String strtext = getArguments().getString("edttext");
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_toolbar, container, false);
}
any help to get rid of the nullpointer would be appreciated, I'm trying to send data to the fragment so it can use the share button and share the data