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);
}
}
1 Answer