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

Bryan Wiedeman
Bryan Wiedeman
10,201 Points

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 82,529 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! :-)