• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How do I change a TextView text?

Kumidan

Newbie
Into a layout I have a TextView
Code:
<TextView
     android:id="@+id/text_routes_details_station_from_value"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginLeft="5dp"
     android:text="@string/text_routes_details_station_from_value"
     android:textAppearance="?android:attr/textAppearanceSmall" />
At runtime I need to be able to change the text of this TextView.
Here how I'm trying to do that
Code:
TextView stFrom = (TextView) findViewById(R.id.text_routes_details_station_from_value);  
stFrom.setText(stationFrom); //stationFrom at the moment is an hardcoded string, so it has a value
This result in an error
02-28 11:18:22.271: E/AndroidRuntime(369): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lcapps.testApp/com.lcapps.testApp.RouteDetailActivity}: java.lang.NullPointerException

....

02-28 11:18:22.271: E/AndroidRuntime(369): at com.lcapps.testApp.RouteDetailActivity.onCreate(RouteDetailActivity.java:25)
line 25 is
stFrom.setText(stationFrom);
 
Back
Top Bottom