Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App The Model-View-Presenter Pattern Adding Custom Constructors

suchita rawat
suchita rawat
1,710 Points

Problem in constructor part

Not able to add ")" at the end of this code.

pages[5] = new Page(R.drawable.page5, R.string.page5

it is showing error.

2 Answers

It's showing an error because the page constructor you have asks for 4 variables,

    public Page(int imageId, int textId, Choice choice1, Choice choice2) {
        this.imageId = imageId;
        this.textId = textId;
        this.choice1 = choice1;
        this.choice2 = choice2;
    }

The part in the parentheses says what the constructor should expect as input. Because these are the last pages, there are no choices, but the code doesn't know that, it just thinks you forgot to include two of the parameters. If you continue with the video, disregarding the errors, he'll show you how to create a second constructor that looks like this.

    public Page(int imageId, int textId) {
        this.imageId = imageId;
        this.textId = textId;
    } 

which will fix your errors.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,705 Points

Hi there,

Can you provide a bit more code for us for more context as to what the problem might be?

For example have you managed to build the main Constructor for the class. That might explain why it's not letting you complete that line of code! :-)