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 trial
hudi ilfeld
1,221 PointsA method im using is causing the app to crash
my app was running just well until i used a custom method of my own called loadPage() in the onCreate() method. wich cuases the app when moving on to next activity to crash! i am struggling to figure out the reason??
//code
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_story);
mImageView = (ImageView)findViewById(R.id.storyImageView);
mTextView = (TextView)findViewById(R.id.storyTextView);
mChoice1 = (Button)findViewById(R.id.choiceButton1);
mChoice2 = (Button)findViewById(R.id.choiceButton2);
loadPage();
Intent intent = getIntent();
name = intent.getStringExtra("name");
if(name == null){
name = "john";
}
Log.d(TAG, name);
}
private void loadPage(){
Page page = mStory.getPage(0);
Drawable drawable = getResources().getDrawable(page.getImageId());
mImageView.setImageDrawable(drawable);
String textPage = page.getText();
textPage = String.format(textPage, name);
mTextView.setText(textPage);
mChoice1.setText(page.getChoice1().getText());
mChoice2.setText(page.getChoice2().getText());
}
}
//end of code.