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 trialJames Richardson
2,496 PointsWhy is my setChioice1 and setChoice2 not recognised? I have spent days trying to figure it out please help!
setChoice1 and setChoice2 are red and the story.java as a red lie underneath here is my code:
package com.jamesrichardson.interactiveadventurestory.model;
import com.jamesrichardson.interactiveadventurestory.R;
import com.jamesrichardson.interactiveadventurestory.model.Choice;
public class Story {
private Page[] mPages;
public Story()
{
mPages = new Page[7];
mPages[0] = new Page();
mPages[0].setImageId(R.mipmap.page0);
mPages[0].setText("test");
mPages[0].setChoice1 (new Choice());
mPages[0].setChoice2 (new Choice());
}
}
PLEASE HELP!
11 Answers
Steve Hunter
57,712 PointsHi James,
Boris is correct. Your Page
class should have the methods setChoice1
and setChoice2
in it.
You must have missed implementing them somehow.
I'd suggest downloading the project files from the previous video, as that puts you at the start of this one from a code perspective. With a bit of tinkering with the package names etc. you should be good to go.
Good luck!
Steve.
Boris Musatov
2,535 PointsHi James!
Your Page class has no setChoice1 and setChoice2 methods.
James Richardson
2,496 PointsThanks Boris!
Harry James
14,780 PointsHey James!
It looks like you have a space here:
setChoice2 (new Choice());
^
on SetChoice1
and setChoice2
. If you get rid of the space, your error should go away.
Hope it helps and, if you have any more problems, give me a shout :)
James Richardson
2,496 PointsHi Harry,
I tried it and I still have the error with this: Cannot resolve method 'setChoice1(com.jamesrichardson.interactiveadventurestory.model.Choice)'
Thank you for your time .
Best Wishes
J
Harry James
14,780 PointsOk. As long as your Choice method is public
and has no errors, the class should be accessible.
Try Cleaning your project. To do this, click on the Build tab and then Clean Project and wait for the Clean to finish:
If you are still having issues, try Invalidating Android Studio's caches. To do this, click on the File tab then Invalidate Caches / Restart and press Invalidate and Restart:
If still after this you are having problems, copy your Choice.java class here and I'll see if there's any problems with it.
James Richardson
2,496 PointsHello again, it didn't work. Thought that it might. Sat here with all fingers crossed (and toes). Here is my Choice.java:
package com.jamesrichardson.interactiveadventurestory.model;
/**
* Created by James on 20/03/2015.
*/
public class Choice {
private String mText;
private int mNextPage;
private Choice mChoice1;
private Choice mChoice2;
private int mImageId;
public String getText() {
return mText;
}
public void setText(String text) {
mText = text;
}
public int getNextPage() {
return mNextPage;
}
public void setNextPage(int nextPage) {
mNextPage = nextPage;
}
public Choice getChoice1() {
return mChoice1;
}
public void setChoice1(Choice choice1) {
mChoice1 = choice1;
}
public Choice getChoice2() {
return mChoice2;
}
public void setChoice2(Choice choice2) {
mChoice2 = choice2;
}
public int getImageId() {
return mImageId;
}
public void setImageId(int imageId) {
mImageId = imageId;
}
}
James Richardson
2,496 PointsThanks again
Steve Hunter
57,712 PointsHi James,
Sorry, but I have no idea what you're trying to get through here as I have not done that course. Apologies!
Your question suggests you have an issue with setChoice1
and setChoice2
. Those are both being called as methods of the first element of the mPage
array. Does the class Page
implement methods called setChoice1
and setChoice2
?
Following that, you're creating two new instances of a class called Choice
. What does that class code look like?
A good way round this is the upload your code into Github so we can see exactly what we're working with. Once we've got your code we can work out what's not working.
Cheers,
Steve.
James Richardson
2,496 PointsOK Will go to GitHub now. Be right back.
Thanks.
Steve Hunter
57,712 PointsPerfect; thanks.
I'm OnlySteveH on there (and Twitter), if you want to invite me to view.
Steve.
James Richardson
2,496 Pointshttps://github.com/jimmystrings1/Treehouse/issues I don;t know how to use GitHub but here is the link to the files.
Many thanks
James
Steve Hunter
57,712 PointsThanks; I'll have a look at that tomorrow. I have work in the morning and need to get some sleep.
Steve.
James Richardson
2,496 PointsHi Steve I have added you. I have posted them under alerts. Many thanks. Night night.
Steve Hunter
57,712 PointsI'll have a look tomorrow ... thanks!
Steve.
James Richardson
2,496 PointsThanks for taking the time Steve really appreciate it!
Steve Hunter
57,712 PointsNo problem!
Steve.
Adilet Zhusupbekov
1,948 PointsHi All,
I have absolutely the same problem as James Richardson. Would you please share what was the resolution of the problem in the code with setChoice? I tried what Harry James suggested but it did not help.
Steve Hunter
57,712 PointsHi Adilet
The problem with this initial query was that the Page
class had no setChoice
methods implemented.
It's probably best you share your code if you are having difficulties, after checking you've got setChoice1
and setChoice2
implemented within the Page
class.
Cheers,
Steve.
Adilet Zhusupbekov
1,948 PointsHi Steve,
Thank you very much! I have already fixed the problem. Just did not pay attention.
Steve Hunter
57,712 PointsGlad you got it fixed!
Any other problems, just give me a shout on here, or on Twitter @OnlySteveH - I'll hear you!
Steve.
Harry James
14,780 PointsHarry James
14,780 PointsGlad to hear you got this fixed now James!
If you could mark Steve's answer as the Best Answer then it will credit him and also let other forum users know that the question has been answered :)