I am extremely new to Android development. I basically have an activity with some buttons, for example "seeTreePicture" and "seeSeaPicture". When I press a button, I want to use a fragment I called "ContentViewer" to display a random tree/sea picture, and also have buttons under the picture to destroy the ContentViewer fragment instance and go back to the menu. The issue is, if I try to use a Fragment Transaction anywhere other than onCreate() of the activity, I get a null pointer exception when I try to access the view in the fragment.

My activity and things related to the fragment:

```
public class SeeActivity extends AppCompatActivity {

DisplayFragment displayFragment;
Button seeTreeButton;
Button seeSeaButton;

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

    seeTreeButton = findViewById(R.id.seeTreeButton);
    seeSeaButton = findViewById(R.id.seeSeaButton);
    displayFragment = new DisplayFragment();

    seeTreeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(R.id.fragmentContainer, displayFragment);
            fragmentTransaction.commit();
            fragmentTransaction.addToBackStack(null);

            displayFragment.changeImage(randomTree);
        }
    });

}

}

```

In my fragment, change image simply changes the image source of the ImageView:

```
public void changeImage(int treeResource)
{
    img = getView().findViewById(R.id.imageView);
    img.setImageResource(treeResource);
}

```

I get a null pointer exception for trying to access the view from getView() in the fragment, meaning that onCreateView wasn't invoked. Yet if I put the same transaction in the onCreate() method of the activity, it works. What am I doing wrong?