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 trialJose Nunez
923 PointsUnderstanding how we constructed the pages in the Constructor
hey guys so i'm a little confused with a certain part of the code.
this is the constructor that we have in our Page class
public Page(int imageId, int textId, Choice choice1, Choice choice2) { this.imageId = imageId; this.textId = textId; this.choice1 = choice1; this.choice2 = choice2; }
it says the constructor takes in 2 integers and 2 Choice objects, cool i understand that. but when call the constructor from our Story class, we put something like this
pages[0] = new Page(R.drawable.page0, R.string.page0, new Choice(R.string.page0_choice1,1), new Choice(R.string.page0_choice2,2));
i dont understand why we are passing a string to the constructor if its expecting an int, or does (R.string.page0) sends an int instead of a string
3 Answers
Mohammed Yehia
Courses Plus Student 9,255 Pointsthat's true, resource in android is represented as integer value so R.string.page0 could be something like this 17864 Everything in the R class is a reference and represented as int value
Alan Kuo
7,697 PointsI asked the same question on Stack Over Flow and got the answer below.
int variables can hold not just numbers but other values like in the case.
If you go check out R.string.page0 you will also find it restored as an int variable.
bohot hard
405 Pointsall resources in android studio are strings but they convert into ints in compile time, thank you