Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


DropDown menu failure

So I have an app where I have a contact form. One of the options is to choose a dropdown menu to choose a value that will show which business service we will provide. I want to then put this as a string in the message of an email. The app works perfect before I put the spinner dropdown menu in. Here is my code:

public class ContactActivity extends AppCompatActivity {

private Button sendButton;
Spinner spinner = (Spinner) findViewById(R.id.contactFormSpinner);

protected void onCreate(Bundle savedInstanceState) {
    sendButton = (Button) findViewById(R.id.sendButton);

    sendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

    private void sendEmail() {
        String name = ((EditText) findViewById(R.id.nameForm)).getText().toString();
        String number = ((EditText) findViewById(R.id.phoneForm)).getText().toString();
        String entry = spinner.getSelectedItem().toString();
        String address = ((EditText) findViewById(R.id.addressForm)).getText().toString();
        String txtMessage = ((EditText) findViewById(R.id.txtMessage)).getText().toString();
        Intent mail = new Intent(Intent.ACTION_SEND);
        mail.putExtra(Intent.EXTRA_EMAIL, new String[]{"generalnick300@gmail.com"});
        mail.putExtra(Intent.EXTRA_SUBJECT, name);
                "Area:"+entry+'\n'+"Phone Number:"+number+'\n'+"Address:"+address+'\n'+"Message:"+txtMessage);

Ben Deitch
Ben Deitch
Treehouse Teacher

What error are you getting?

1 Answer

The app crashes in general. Before I implement the spinner it does not

Ben Deitch
Ben Deitch
Treehouse Teacher

When an app crashes, the error that caused the crash is recorded in the Logcat. Is there an error being logged there?