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 Blog Reader Android App Using Intents to Display and Share Posts Easy Sharing with Intents

Javier Briones
seal-mask
.a{fill-rule:evenodd;}techdegree
Javier Briones
Front End Web Development Techdegree Student 29,674 Points

Help

I can't figure what's wrong with my solution. Here's my code

if(itemId == R.id.action_share)  
{
    // Add code here!
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    String Hello = "Hello";
    shareIntent.putExtra(Intent.EXTRA_TEXT, Hello);
    startActivity(Intent.createChooser(shareIntent, R.string.chooser_title));
}

And here's the error I get:

JavaTester.java:58: cannot find symbol
symbol  : method createChooser(android.content.Intent,int)
location: class android.content.Intent
    startActivity(Intent.createChooser(shareIntent, R.string.chooser_title));
                        ^
1 error

I still don't understand what is wrong with my code

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You need to pass in an actual String as the 2nd parameter, not just the string ID:

startActivity(Intent.createChooser(shareIntent, getString(R.string.chooser_title)));

It's not totally clear, but the error message helps track this down:

symbol : method createChooser(android.content.Intent,int)

It's saying that it can't find a createChooser() method that has an "int" as the 2nd parameter.