Android Studio: Unable to instantiate activity ComponentInfo

I am trying to open a new Activity in Android Studio on a Button Press.

public class Home extends AppCompatActivity {

    private Button button;

    protected void onCreate(Bundle savedInstanceState) {

        button = findViewById(;
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
    public void addSubject(){
        Intent intent = new Intent(this, AddSubject.class);

I get the following error:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.smarkmarks/com.example.smarkmarks.AddSubject}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

Read more here:

Content Attribution

This content was originally published by Herbix at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: