I am new to android development and my code is not working how it should. The following does not update the text I have in a string called otp1. I think it is firing the exception, is there a way to see if it is? Also, any tips on why it is not working would be great.
package com.josephflynn.HelloWorld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
final TextView textViewToChange = (TextView) findViewById(R.string.otp1);
textViewToChange.setText("otp");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/otp1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is my first Android Application!" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add this clickable button!" />
</LinearLayout>
You need to specify a valid view ID here:
Did you mean to do this?
If you can’t figure it out, post your layout too. If you’re trying to see the exception, get rid of that try/catch. Then after it crashes, look in LogCat (Window -> Show View -> LogCat).