Skip to content Skip to sidebar Skip to footer

Unfortunately Myfirstproject Stopped Working Error In Java

I know this is a very simple question for you experts,but please forgive me.Im very new to this android platform. I tried to display a string in a textview when a button is clicked

Solution 1:

I have done some modifications in onCreate().here i am making a textview which you left.Do that and say is it working ?

@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mybtn= newButton(this);
        mybtn.setOnClickListener(this);
        txtView=newTextView(this);
      //  printmyname();LinearLayout ll=newLinearLayOut(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(mybtn);
ll.addView(txtView);
        setContentView(ll);
       // setContentView(R.layout.main);
    }

HTH :)

Solution 2:

You have not created a new object of TextView.

txtView = new TextView(this);

Else use findViewById if you've created the text View in your xml files.

txtView = (TextView)findViewById(R.id.TextView1);

Post a Comment for "Unfortunately Myfirstproject Stopped Working Error In Java"