setChecked in CheckBox returns java.lang.NullPointerException

view story

http://stackoverflow.com – I hope that you can help me with this. I have a XML with a checkBox control and I want change its to checked by code. When Android Studio compiles, the code has an error in "cb.setChecked(true)". FATAL EXCEPTION: main java.lang.NullPointerException CheckBox cb = (CheckBox) findViewById(R.id.checkBox); cb.setChecked(true); XML file. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" (HowTos)