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 trialRubio Salinas
3,051 Points"Cannot resolve symbol 'storyImageView'" Building an interactive story app. Loading the first page
I dont have issues with anything else in the code, just with the storyImageView. Any help would be greatly appreciated. Here is my code.
public class StoryActivity extends AppCompatActivity {
public static final String Tag = StoryActivity.class.getSimpleName();
private Story story;
private ImageView storyImageView;
private TextView storyTextView;
private Button choice1Button;
private Button choice2Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story);
storyImageView = (ImageView) findViewById(R.id.storyImageView); // I get an error here on this line for storyImageView
storyTextView = (TextView)findViewById(R.id.storyTextView);
choice1Button = (Button)findViewById(R.id.choice1Button);
choice2Button = (Button)findViewById(R.id.choice2Button);
Intent intent = getIntent();
String name = intent.getStringExtra(getString(R.string.key_name));
if (name == null || name.isEmpty()) {
name = "Friend";
}
Log.d(Tag, name);
story = new Story();
loadPage(0);
}
private void loadPage(int pageNumber) {
Page page = story.getPage(pageNumber);
}
}
1 Answer
Maciej Czuchnowski
36,441 PointsYou have a space here:
(ImageView) findViewById(R.id.storyImageView);
and typecasting should not have any space there, just like you can see in the lines that follow. It should be:
(ImageView)findViewById(R.id.storyImageView);
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsAnother option is that you don't have an object called
storyImageView
in youractivity_main.xml
.Rubio Salinas
3,051 PointsRubio Salinas
3,051 Pointshow would I add it to the xml?