I got lots of NPEs and was wondering how you manage this common task.
There is a button in my fragment, here the WelcomeFragment.
The button will clicked and the event is handled in the MainActivity class.
The fragment is a NPE, the view, too ...
Here is my code snippet of my MainActivity:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
...
WelcomeFragment welcomeFragment = (WelcomeFragment) getFragmentManager().findFragmentByTag(WelcomeFragment.WELCOME_FRAGMENT_TAG);
if (welcomeFragment == null){
welcomeFragment = new WelcomeFragment();
}
View view = welcomeFragment.getView();
if (view == null){
view = new View(this);
}
TextView text1 = (TextView) view.findViewById(R.id.welcomeFragmentHeader);
text1.setText(newTextToShow + resStr);
break;
...