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!

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

Android Android Fragments Ingredients and Directions The Directions Fragment

chandrashekhar singh
chandrashekhar singh
507 Points

I 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);


        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);
            if (checkedBoxex[i]) {


4 Answers

Javier Mera
Javier Mera
16,472 Points

You have a semicolon at the end of your if statement my friend.

Harrison Court
Harrison Court
4,232 Points

Please don't bring back an old post

Jason Anders
Jason Anders
Treehouse Moderator 145,855 Points

Harry 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.


Treehouse Community Moderator

Harrison Court
Harrison Court
4,232 Points

I can't read your code correctly, do ``` (three backticks, above the escape button) so I could see it better.

  • Harry
Jason Anders
Jason Anders
Treehouse Moderator 145,855 Points

First, 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.


You have to put Int i = 0; outside the for loop in setupCheckBoxes Method