 <p>Your UI elements in Fragment_Main.xml. You get NullPointerException because you set activity_main.xml as layout for MainActivity: <code>setContentView(R.layout.activity_main);</code>. Move the layout from Fragment_Main.xml to activity_main.xml.</p>