So I'm trying to change my layout with a button using fragment, but I can't get it to work, probably because I don't really understand how it works. I'm very new to programming overall so I have a bit trouble understanding some stuff. Anyways, this is what I want to do.

MainActivity

```
public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    Fragmenttwo thenewfrag = new Fragmenttwo();
    fragmentTransaction.replace(android.R.id.content, thenewfrag);

    Button splay = (Button) findViewById(R.id.splay);

    splay.setOnClickListener(new View.OnClickListener(){
    public void onClick(View v) {
          FragmentManager fragmentManager = getFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

          Fragmentone newfrag = new Fragmentone();
          fragmentTransaction.replace(android.R.id.content, newfrag);

          fragmentTransaction.commit();
    }
});
fragmentTransaction.commit();
}
}

```

Fragmentone

```
public class Fragmentone extends Fragment {

 public Fragmentone() {}

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     View view = inflater.inflate(R.layout.mainmenu, container, false);
     return view;

    }
}

```

Fragmenttwo

```
public class Fragmenttwo extends Fragment{

 public Fragmenttwo() {}

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     View view = inflater.inflate(R.layout.start_board, container, false);
     return view;

    }
}

```

mainmenu.xml

```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainmenu" >

<Button
    android:id="@+id/splay"
    android:layout_width="195dp"
    android:layout_height="64dp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

```

LogCat (I get NullPointerException on the onClickLitsener? Error happends when button pressed)

```
E/AndroidRuntime(2001): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gerfort.gerfortrps/com.gerfort.gerfortrps.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference

```

Any ideas how to do fix this? Or how to change layout using a button?