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 an Interactive Story App The Rest of the Story Maintaining a Custom Back Stack

can't use onBackPressed??

in the interactive app story i can't use the onBackPressed it is saying ; missing but even if i am giving ; nothing is happening can someone help me?????

can someone please help this is my code ``` import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

import com.pratyush.interactivestory.R; import com.pratyush.interactivestory.model.page; import com.pratyush.interactivestory.model.story;

import java.util.Stack;

public class StoryActivity extends AppCompatActivity {

private story Story;
private ImageView storyImageView;
private TextView storyTextView;
private Button choice1Button;
private Button choice2Button;
private String name;
private Stack<Integer> pageStack = new Stack<Integer>();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);

    storyImageView = findViewById(R.id.storyImageView);
    storyTextView = findViewById(R.id.storyTextView);
    choice1Button = findViewById(R.id.choice1Button);
    choice2Button = findViewById(R.id.choice2Button);

    Intent intent = getIntent();
    name = intent.getStringExtra(getString(R.string.key_name));
    if (name==null || name.isEmpty()) {
        name="Friend";
    }

    Story = new story();
    loadpage(0);

}

private void loadpage(int pageNumber) {
    pageStack.push(pageNumber);
    final page Page = story.getpage(pageNumber);
    Drawable image = ContextCompat.getDrawable(this,Page.getImageId());
    storyImageView.setImageDrawable(image);

    String pageText = getString(Page.getTextId());
    pageText = String.format(pageText,name);

    storyTextView.setText(pageText);
    if (Page.isFinalPage()){
        choice1Button.setVisibility(View.INVISIBLE);
        choice2Button.setText(R.string.play_again);
        choice2Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadpage(0);
            }
        });
    }
    else {

        choice1Button.setText(Page.getChoice1().getTextId());
        choice1Button.setVisibility(View.VISIBLE);

        choice1Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int nextPage = Page.getChoice1().getNextPage();
                loadpage(nextPage);
            }
        });
        choice2Button.setText(Page.getChoice2().getTextId());
        choice2Button.setVisibility(View.VISIBLE);

        choice2Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int nextPage = Page.getChoice2().getNextPage();
                loadpage(nextPage);
            }
        });
    }

    @Override
    public void onBackPressed() {
        pageStack.pop();
        if (pageStack.isEmpty()) {
            super.onBackPressed();
        } else {
            loadpage(pageStack.pop());
        }
    }









}

}```

it is saying on public void onBackPressed() { ; this is expected i don't know