android creating text view dynamically -


i'm new android. playing basic things. here's code

public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     linearlayout = (linearlayout) findviewbyid(r.id.linearlayout);     setcontentview(r.layout.activity_display_message);     // message intent     intent intent = getintent();     string status = intent.getstringextra(myactivity.extra_message);      textview textview = new textview(this);     textview.settextsize(40);     textview.settext(status);     textview.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content));     linearlayout.addview(textview); } 

xml:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/linearlayout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#ff99ccff"     android:orientation="vertical" > </linearlayout> 

when run on phone says, "unfortunately, app has stopped"

change order like

setcontentview(r.layout.activity_display_message); linearlayout = (linearlayout) findviewbyid(r.id.linearlayout); 

you must setcontentview(...) first , initialize views.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -