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 trialLuka Nixon
2,303 PointsIssues with drawables
For some reason my drawables have and error when i try to call them, i.e : R.drawable.page0.
The "page0" has a red squiggly under it and tells me to rename it. It does it for all my drawables on my Story activity. I have all the drawables in my res/drawables so i don't know whats wrong here. Here is the code:
package model; import android.R; import model.page; import model.Choice; import com.lukan.signalsfrommars.R.id; import com.lukan.signalsfrommars.R.layout; import com.lukan.signalsfrommars.R.string;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.text.Editable; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.os.Build; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Story { private page[] mPages;
public Story() {
mPages = new page[7];
mPages[0] = new page(
R.drawable.page0,
"On your return trip from studying Saturn's rings, you hear a distress signal that seems to be coming from the surface of Mars. It's strange because there hasn't been a colony there in years. Even stranger, it's calling you by name: \"Help me, %1$s, you're my only hope.\"",
new Choice("Stop and investigate", 1),
new Choice("Continue home to Earth", 2));
mPages[1] = new page(
R.drawable.page1,
"You deftly land your ship near where the distress signal originated. You didn't notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century.",
new Choice("Explore the cave", 3),
new Choice("Explore the rover", 4));
mPages[2] = new page(
R.drawable.page2,
"You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low.",
new Choice("Head back to Mars to investigate", 4),
new Choice("Continue home to Earth", 6));
mPages[3] = new page(
R.drawable.page3,
"Your EVA suit is equipped with a headlamp, which you use to navigate the cave. After searching for a while your oxygen levels are starting to get pretty low. You know you should go refill your tank, but there's a very faint light up ahead.",
new Choice("Refill at ship and explore the rover", 4),
new Choice("Continue towards the faint light", 5));
mPages[4] = new page(
R.drawable.page4,
"The rover is covered in dust and most of the solar panels are broken. But you are quite surprised to see the on-board system booted up and running. In fact, there is a message on the screen: \"%1$s, come to 28.543436, -81.369031.\" Those coordinates aren't far, but you don't know if your oxygen will last there and back.",
new Choice("Explore the coordinates", 5),
new Choice("Return to Earth", 6));
mPages[5] = new page(
R.drawable.page5,
"After a long walk slightly uphill, you end up at the top of a small crater. You look around, and are overjoyed to see your favorite android, %1$s-S1124. It had been lost on a previous mission to Mars! You take it back to your ship and fly back to Earth.");
mPages[6] = new page(
R.drawable.page6,
"You arrive home on Earth. While your mission was a success, you forever wonder what was sending that signal. Perhaps a future mission will be able to investigate...");
}
}
4 Answers
James Simshaw
28,738 PointsHello,
While in you Story.java file, could you try optimizing your imports? There's a lot of imports that look extraenous and possibly some missing imports. While on the Story.java file could you hit Ctrl - Alt - O(assuming you are in Android Studio on Windows or Linux). If you are still having issues after that, please post what the updated code ended up being for Story.java. If you could also post the code using markdown that would greatly help(it provides proper formatting of code and color coding). There is a Markdown Cheatsheet link below the posting window, but for starters, you can use "java" to start the code(without the quotation marks) and then end it with "
" (again, without the quotation marks). I like to leave a newline after the start and before the end as well.
James Simshaw
28,738 PointsHello,
I think the folder you want to have your drawables in is res/drawable not res/drawables. If you have different images for different dpi settings then you'd want them in res/drawable-mdpi, res/drawable-hdpi, etc.
If they are located in the res/drawable folder, I'd then recommend checking that the filenames are page0.png(or .jpg, etc). If this doesn't help, please let us know and we can assist you further.
Luka Nixon
2,303 PointsSorry about getting back to you so late, but yes that was a typo, my drawables are in res/drawable-hdpi, etc. The image files names are .png so that is not the problem.
Luka Nixon
2,303 PointsSorry about getting back to you so late, but yes that was a typo, my drawables are in res/drawable-hdpi, etc. The image files names are .png so that is not the problem.
James Simshaw
28,738 PointsTaking a closer look at the code. I'm noticing you're using new page(). Classes in Java are expected to be capitalized so you might need to go back to your Page.java file and change that if it is lowercase and then update every time you call Page. You might also want to make sure that in your constructor for Page you are expecting an int value as the first parameter. If neither of these help, could you also post your Page.java file?
Luka Nixon
2,303 PointsOkay i changed them all to Page. Here is my Page.java file
package model;
import model.Page; import model.Choice;
public class Page {
private int mImageId;
private Choice mChoice1;
private Choice mChoice2;
private String mText;
private boolean mIsFinal = false;
public Page(int ImageId, String Text, Choice choice1, Choice choice2){
mImageId = ImageId;
mText = Text;
mChoice1 = choice1;
mChoice2 = choice2;
}
public Page(int ImageId, String Text){
mImageId = ImageId;
mText = Text;
mChoice1 = null;
mChoice2 = null;
mIsFinal = true;
}
public int getmImageId() {
return mImageId;
}
public void setmImageId(int mImageId) { this.mImageId = mImageId; }
public String getmText() { return mText; }
public void setmText(String mText) { this.mText = mText; }
public Choice getmChoice1() { return mChoice1; }
public void setmChoice1(Choice mChoice1) { this.mChoice1 = mChoice1; }
public Choice getmChoice2() { return mChoice2; }
public void setmChoice2(Choice mChoice2) { this.mChoice2 = mChoice2; } public boolean ismIsFinal() { return mIsFinal; } public void setmIsFinal(boolean mIsFinal) { this.mIsFinal = mIsFinal; }
}
James Simshaw
28,738 PointsIs there any way you could get your full code up on anywhere like Github? It would allow me to see everything and not have to guess at what could be going wrong.
James Simshaw
28,738 PointsAlso, another pointer on style, for variable names, you want to have the first letter of variable names lowercased, but it shouldn't be causing your problem right now.
Luka Nixon
2,303 PointsDo you have to install Github to publish the code?
James Simshaw
28,738 PointsYou should just need to create an account(and maybe a repository) and then you should be able to use Android Studio for the rest. The course Android Tools goes over this in more detail if this is your first time using Github.
Luka Nixon
2,303 PointsSo because I do all my programming on my schools computers i am unable to install Git