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!

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 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
Jonathan Grieve
Treehouse Moderator 91,250 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! :-)