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
Farouk Charkas
1,957 PointsWhy is my app crashing again? Help appreciated!
This is the part that is crashing:
//What will happen
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
ImageButton advancedButton = (ImageButton) findViewById(R.id.advancedButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.advanced);
}
};
advancedButton.setOnClickListener(listener);
ImageButton imageButtonRip = (ImageButton) findViewById(R.id.imageButtonRip);
View.OnClickListener mamans = new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.activity_main);
}
};
imageButtonRip.setOnClickListener(mamans);
}
Farouk Charkas
1,957 PointsAny ideas why Jon Kussmann and Gloria Dwomoh
1 Answer
Jon Kussmann
Courses Plus Student 7,254 PointsYou are asking your Activity to find R.id.imageButtonRip while the layout is still R.layout.activity_main. You didn't post your layout files, but I imagine that button only exists in the layout R.layout.advanced
Is there a reason why you aren't just switch activities instead of attempting to change the layout of one activity?
Farouk Charkas
1,957 PointsTo be honest Jon Kussmann,
I really do not know. Bu it works! Thank you so so much! I do have a bug, I can only do it once, but that is okay!
Farouk Charkas
1,957 PointsFarouk Charkas
1,957 PointsThis is my logcat, the caused by part: