im trying to change the text of an activity 2 upon starting another (different) activity 1 with setText(), but as soon as activity 1 starts it crashes (it is opened through the click of a button). the error message is
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(int)' on a null object reference
all solutions i found so far have not worked - either because they were for something else (i often saw something for a navigationdrawer, which i am not using), because they had nothing to do with my code or i had it already implemented.
activity 1:
public class ActivityTL extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tl);
final TextView text1 = (TextView) findViewById(R.id.textView1);
text1.setText(R.string.testB1);
final TextView text2 = (TextView) findViewById(R.id.textView2);
text2.setText(R.string.testB2);
final TextView text3 = (TextView) findViewById(R.id.textView3);
text3.setText(R.string.testB3);
final Intent intent = new Intent(this, testA.class);
final ImageButton imageButtonA = findViewById(R.id.imageButtonA);
imageButtonA.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(intent);
}
});
}
}
strings.xml:
<string name="testA1">1</string>
<string name="testA2">2</string>
<string name="testA3">3</string>
<string name="testB1">4</string>
<string name="testB2">5</string>
<string name="testB3">6</string>
if you need other information, please tell me and i will add it. thank you in advance!