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 trialGAURAV DOBHAL
6,155 PointsError initializing mPages
Q.) In the Story Class if I try to initialise mPages outside of the Story constructor it throws multiple errors. I have given the details below. I am wondering why?
public class Story {
private Page[] mPages;
private Choice[] mChoices;
mPages = new Page[7];
//Errors: mPages=Class unknown
new=Unexpected Token
[7]=identifier expected
1 Answer
Jacob Bergdahl
29,119 PointsAre you initializing it in onCreate(), a different method, or out in the open? You cannot instantiate variables outside of a method.