I have an imageButton on my xml:
<ImageButton
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginTop="10dp"
    android:id="@+id/star"
    android:background="@drawable/star"
    android:layout_below="@+id/releaseDate"
    android:layout_alignLeft="@+id/releaseDate"
    android:layout_alignStart="@+id/releaseDate" />  
I want to add the action of the button, but the problem is that the imageButton I created is returning null when fetching the imagebutton on xml with findViewById:
public class DetailActivity extends AppCompatActivity {
    ImageButton ib;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        if(savedInstanceState == null){
            getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new DetailActivityFragment())
                .commit();
            ib = (ImageButton)findViewById(R.id.star);
            if(ib != null) {
                ib.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.v(null, "Image Clicked!");
                }
            });
        }
    }
}
