vendredi 8 janvier 2016

NullPointerException when referencing textView [duplicate]

This question already has an answer here:

I'm getting a NullPointerException where the two ** are and I can't figure out why. I've tried inflating the layout, and then setting the string to the textView with no success. To my knowledge, I understand that this exception is being thrown because the layout isn't fully inflated and there is no textView to set the string to (?), but then the correct activity is inflated when I test it without setting the text to the tv which is confusing me. Any help is appreciated. Here's the code in my Main Activity:

  if ("String 1".equals(currentObject)) {
                setContentView(R.layout.activity_activityone);
                **tv1.setText(string);**
            } else if ("String 2".equals(currentObject)) {
                setContentView(R.layout.activity_activitytwo);
                **tv2.setText(stringtwo);**
            }

Aucun commentaire:

Enregistrer un commentaire