I have following main.xml of layout
<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:id="@+id/textview01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
and I am trying to retrieve the text i.e. @string/hello by using the following code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv= (TextView) findViewById(R.id.textview01);
String input= tv.getText().toString();
Log.d("Info",input);
but I am not able to see the output. Application is crashing with NULL Exception error at the String input = tv.getText(
You need to call
before calling
findViewById