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 trialchandrashekhar singh
507 PointsI am getting this problem.
Process: com.csing1s.myapplication, PID: 7024 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean[] android.os.Bundle.getBooleanArray(java.lang.String)' on a null object reference
Code is here
mCheckBoxes = new CheckBox[contents.length];
boolean[] checkedBoxex = new boolean[mCheckBoxes.length];
if(savedInstanceState != null && savedInstanceState.getBooleanArray(KEY_CHECKED_BOXEX)!=null);
{
checkedBoxex = savedInstanceState.getBooleanArray(KEY_CHECKED_BOXEX);
}
setupCheckBoxes(contents,linearLayout,checkedBoxex);
return view;
}
private void setupCheckBoxes(String[] contents, ViewGroup container, boolean[] checkedBoxex) {
for (String in : contents) {
int i = 0;
mCheckBoxes[i] = new CheckBox(getActivity());
mCheckBoxes[i].setPadding(8, 16, 8, 16);
mCheckBoxes[i].setTextSize(20f);
mCheckBoxes[i].setText(in);
container.addView(mCheckBoxes[i]);
if (checkedBoxex[i]) {
mCheckBoxes[i].toggle();
}
i++;
}
4 Answers
Javier Mera
16,472 PointsYou have a semicolon at the end of your if statement my friend.
Harrison Court
4,232 PointsI can't read your code correctly, do ``` (three backticks, above the escape button) so I could see it better.
- Harry
Jason Anders
Treehouse Moderator 145,860 PointsFirst, I edited your post include markdown so the code can be properly read in the forums. Please see the Markdown Cheatsheet to see how to post code.
As for your error,
I would double check the spelling and naming... some are checkBoxes (with an 's') and some are checkedBoxex (with an 'x'). This could lead to the described error.
akshay reddy
5,238 PointsYou have to put Int i = 0; outside the for loop in setupCheckBoxes Method
Harrison Court
4,232 PointsHarrison Court
4,232 PointsPlease don't bring back an old post
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHarry Court
Posts on Treehouse don't close when they get to a certain 'age.'
Students are more than welcome (and encouraged) to add their comments or solutions on posts that are any "age." Otherwise, Treehouse would be designed to prevent posting after a certain time period.
I, myself, have added to posts that are upwards of a year old or more. This is what Treehouse is about. Adding to posts (regardless of how old they are) adds to and enhances the Treehouse learning experience. It also provide more information for students that happen across an older post.
I'm sorry if you find this an annoyance, but adding to any post is encouraged.
Edit: If you don't wish to receive notifications when someone adds to a post that you have participated in, you can click the "Unfollow Discussion" in the upper-right corner of the post, and you will no longer receive any notifications of added postings.
Jason
Treehouse Community Moderator