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 Starting the App Introducing the Project

Ricky Sparks
Ricky Sparks
22,249 Points

My Java code for Message-Destruction App won't pass?

The code below is excerpted from the finished Ribbit app. There are two errors in it: find and fix them! Read line by line, even character by character if you have to.

Ricky Sparks
Ricky Sparks
22,249 Points

Intent recipientsIntent = new Intent(this, RecipientsActivity.class); recipientsIntent.setData(mMediaUri); // mMediaUri is defined and set elsewhere recipientsIntent.putExtra("file_type", "image"); startActivity(Intent);

Ricky Sparks
Ricky Sparks
22,249 Points

Yes thanks for asking :D

4 Answers

This is actually not called the "My Java" challenge, but the "Introducing the Project" challenge: http://teamtreehouse.com/library/introducing-the-project-2

The starting (given) warmup.java code was:

Intent recipientsIntent = new Intent(this, RecipientsActivity.class)
recipientsIntent.setData(mMediaUri); // mMediaUri is defined and set elsewhere
recipientsIntent.putExtra("file_type", "image");
startActivity(thisIsTheWrongIntent);

You'll notice that Ricky correctly got the first edit in his posted code above by adding a semi-colon to the end of the first line:

Intent recipientsIntent = new Intent(this, RecipientsActivity.class); 

Daniel then provided the needed adjustment to the last line.

However I looked up the github version of this code here: https://github.com/treehouse/android-ribbit/blob/master/src/com/teamtreehouse/ribbit/MainActivity.java

Here is the chunk of code that was excerpted:

Intent recipientsIntent = new Intent(this, RecipientsActivity.class);
recipientsIntent.setData(mMediaUri);String fileType;
if (requestCode == PICK_PHOTO_REQUEST || requestCode == TAKE_PHOTO_REQUEST) {
  fileType = ParseConstants.TYPE_IMAGE;
  }
  else {
  fileType = ParseConstants.TYPE_VIDEO;
  }
recipientsIntent.putExtra(ParseConstants.KEY_FILE_TYPE, fileType);
startActivity(recipientsIntent);

You'll notice that the third line reads not:

recipientsIntent.putExtra("file_type", "image");

but this line instead:

recipientsIntent.putExtra(ParseConstants.KEY_FILE_TYPE, fileType);

However, taking the time to look up the actual code won't help you because this actually (real) MainActivity.java code will not pass the challenge test.

So I really don't know what the purpose of this challenge was/is...?

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Ricky

I think the intent variable is named recipientsIntent not simply intent

startActivity(recipentsIntent);

Hope this helps

Daniel

Charles Welbeck
PLUS
Charles Welbeck
Courses Plus Student 9,745 Points
// The code below is an excerpt from this finished app

Intent recipientsIntent = new Intent(this, RecipientsActivity.class);
recipientsIntent.setData(mMediaUri); // mMediaUri is defined and set elsewhere
recipientsIntent.putExtra("file_type", "image");
startActivity(recipentsIntent);
Joe Goodall
Joe Goodall
3,483 Points

Sorry to be pedantic but there is an 'i' missing from the last line.

Should read startActivity(recipientsIntent); rather than startActivity(recipentsIntent);.

// The code below is an excerpt from this finished app

Intent recipientsIntent = new Intent(this, RecipientsActivity.class); recipientsIntent.setData(mMediaUri); // mMediaUri is defined and set elsewhere recipientsIntent.putExtra("file_type", "image"); startActivity( recipientsIntent);

Intent recipientsIntent = new Intent(this, RecipientsActivity.class); recipientsIntent.setData(mMediaUri); // mMediaUri is defined and set elsewhere recipientsIntent.putExtra("file_type", "image"); startActivity( recipientsIntent);