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 Build a Self-Destructing Message Android App Sending Messages Sending the Message

Sending the message code challenge

I am trying to do the second task in this code challenge and I'm not sure what I'm doing wrong here is my code:

import android.app.Activity;
import android.widget.EditText;
import android.widget.Toast;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;

public class MainActivity extends Activity {

    protected EditText mDescriptionField;


    protected SaveCallback mSaveCallback = new SaveCallback() {
        @Override
        public void done(ParseException e) {
            Toast.makeText(MainActivity.this, "Item saved!", Toast.LENGTH_SHORT).show();
        }
    };

    // Some code omitted!

    public void save() {
        ParseObject mTask = new ParseObject("Task");
        String description = mDescriptionField;

    }
}

11 Answers

You left out the second i in "description"

I think it may have been one of the videos before this one where he talks about getting a string from an EditText object. Take a look at http://developer.android.com/reference/android/widget/EditText.html to see the methods that are available to you on mDescriptionField. You'll need to use one of those methods. After you call that method, you'll then need to call toString() on the returned value since the returned value is not a string.

Remember, you can't assign something to a string variable that is not a string.

Marc-Oliver Gern
Marc-Oliver Gern
8,747 Points

I had some difficulties as well but figured it out using the eclipse editor:

public void save() {
// Declare object on parse.com
    ParseObject todo = new ParseObject("Task");
    // Get value from EditText and store it in description (as string)
    String description = mDescriptionField.getText().toString();
    // Now take the string from description and put it into the ParseObject
    todo.put("description", mDescriptionField.getText().toString());
    // Save it using methods outlined above
    todo.saveInBackground(mSaveCallback);
}

You can't do String description = mDescriptionField; because mDescriptionField is an EditText object, so you can't assign it directly to a string variable. You have to get the text from mDescriptionField and then assign that to description. There's a part in the video where Ben talks about how to do this.

Hello Ben

Ive tried to figure it out by going back through the video but I could find it. I also tried

'''java String description = (EditText)mDescriptionField; '''

but that didn't work either.

I remember now. I put the getText().toString() extension and it worked out. Thank you for your help.

I don't know why I'm so horribly stuck on this code challenge on part 3 I put down the code below which I believe is right but nothing is working

'''java

import android.app.Activity; import android.widget.EditText; import android.widget.Toast; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback;

public class MainActivity extends Activity {

protected EditText mDescriptionField;

protected SaveCallback mSaveCallback = new SaveCallback() {
    @Override
    public void done(ParseException e) {
        Toast.makeText(MainActivity.this, "Item saved!", Toast.LENGTH_SHORT).show();
    }
};

// Some code omitted!

public void save() {
  ParseObject mTask = new ParseObject("Task");
  String description = mDescriptionField.getText().toString();
  mTask.put("descripton", description);

}

}

'''

check the spelling of description

Far smarter than I sir

Thanks !

this should work:

String description = mDescriptionField.getText().toString();