What could possibly be causing this NPE in onCreate?

Posted by Adam Johns on Stack Overflow See other posts from Stack Overflow or by Adam Johns
Published on 2013-11-07T22:21:39Z Indexed on 2013/11/08 3:54 UTC
Read the original article Hit count: 182

I am getting an NPE in onCreate of the following file (MySubActivity):

public class MySubActivity extends MySuperActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myTextView.setText(getResources().getString(R.string.myString));
    }
}

MySuperActivity:

public class MySuperActivity extends Activity {
    protected TextView myTextView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_layout);

        myTextView = (TextView)findViewById(R.id.myTextViewid);
    }
}

The strange thing is that I have never seen this crash while testing the app. The page works fine when I test it. However I got a crash report from Google notifying me of the crash. I cannot reproduce it, and I have no idea under what scenario this crash could happen. Seeing as how it works for me, the resource ids and string names etc. must be correct.

The only thing that came across my mind was that maybe the user had their phone set to a different language, so it couldn't properly pull the resources. However, there are default resources for all of them, and I tested changing the language of my emulator and it didn't crash. Any ideas?

© Stack Overflow or respective owner

Related posts about android

Related posts about nullpointerexception