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

Android

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);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact);
    sendButton = (Button) findViewById(R.id.sendButton);

    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            sendEmail();
        }
    });
}



    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);
        mail.putExtra(Intent.EXTRA_TEXT,
                "Area:"+entry+'\n'+"Phone Number:"+number+'\n'+"Address:"+address+'\n'+"Message:"+txtMessage);
        mail.setType("message/rfc822");
        startActivity(mail);
    }

}
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?