Reputation: 79
I am developing a camera app. I want to display a text view on the camera preview. If I add the text view, the app will show the text view with the default text. When I do setText, the app is crashing. Can any body tell what might be the reason for this?
<TextView android:layout_width="wrap_content" android:id="@+id/textView1"
android:layout_height="wrap_content" android:text="Text"
android:layout_gravity="center" android:paddingTop="25dp"
android:textSize="20dp" android:textStyle="bold" android:textColor="#FFFFFF" />
java code:
TextView text = (TextView) findViewById(R.id.textView1);
text.setText("hi");
If I comment out setText line then app will display the default text.
Upvotes: 0
Views: 809
Reputation: 1526
Have you called setContentView()
before calling findViewById()
?
Upvotes: 1
Reputation: 57173
Your log suggests that textView1 is not available at that stage of onCreate(). When do you load the layout? Can you setText() later?
Upvotes: 1