Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

        }
            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
Javier Mera
16,472 Points

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

Harry Court
Harry Court
3,645 Points

Please don't bring back an old post

Jason Anders
Jason Anders
Treehouse Moderator 145,624 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.

Jason

Treehouse Community Moderator

Harry Court
Harry Court
3,645 Points

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

  • Harry
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,624 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.

:dizzy:

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