When I try to run the following code I get an error. The emulator gives me this error message and then the app force closes: The application has stopped unexpectedly. What is wrong?
import edu.chl.dat255.bluebanana.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ProMan extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout) findViewById(R.layout.main);
TextView t = new TextView(getApplicationContext());
t.setText("Hello world");
layout.addView(t);
}
}
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
In your xml file main xml layout android:id="@+id/mainLayout"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With