Arraylist from other class is empty : <p>I'm trying to access an Arraylist from a different class. This works but the Arraylist is always empty.</p>

<pre><code>public class CategoryFragment extends Fragment {

private List&lt;Category&gt; lsCategory;

public CategoryFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    lsCategory = new ArrayList&lt;&gt;();

    lsCategory.add(new Category(1, getString(R.string.cat_school), R.drawable.cat_school_filled_48dp));
    lsCategory.add(new Category(2, getString(R.string.cat_food), R.drawable.cat_food_filled_48dp));
    lsCategory.add(new Category(3, getString(R.string.cat_sports), R.drawable.cat_sports_filled_48dp));
    lsCategory.add(new Category(4, getString(R.string.cat_travel), R.drawable.cat_travel_filled_48dp));
    lsCategory.add(new Category(5, getString(R.string.cat_hobbies), R.drawable.cat_sports_filled_48dp));
    lsCategory.add(new Category(6, getString(R.string.cat_countries), R.drawable.cat_countries_filled_48dp));
    lsCategory.add(new Category(7, getString(R.string.cat_numbers), R.drawable.cat_countries_filled_48dp));
    lsCategory.add(new Category(8, getString(R.string.cat_animals), R.drawable.cat_animals_filled_48dp));
    lsCategory.add(new Category(9, getString(R.string.cat_nature), R.drawable.cat_nature_filled_48dp));

    View v = inflater.inflate(R.layout.fragment_category, container, false);
    RecyclerView myRv = (RecyclerView) v.findViewById(R.id.main_recyclerView);
    CategoryRecyclerViewAdapter myAdapter = new CategoryRecyclerViewAdapter(getActivity(), lsCategory);
    myRv.setLayoutManager(new GridLayoutManager(getActivity(), 3));
    myRv.setAdapter(myAdapter);
    return v;
}

public List&lt;Category&gt; getLsCategory() {
    return lsCategory;
}
</code></pre>

<p>}</p>

<p>In this other class I try to acces this Arraylist.</p>

<pre><code>public class FlashcardFragment extends Fragment {

private List&lt;Flashcard&gt; lsFlashcard;
private CategoryFragment categoryFragment;

public FlashcardFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    lsFlashcard = new ArrayList&lt;&gt;();
    categoryFragment = new CategoryFragment();
    List&lt;Category&gt; calledList = categoryFragment.getLsCategory();

    if(calledList != null &amp;&amp; !calledList.isEmpty()){
        for(int i = 0; i &lt; calledList.size(); i++){
            int number = calledList.get(i).getId();

            if(number == 1){
                lsFlashcard.add(new Flashcard(1, getString(R.string.school_backpack), R.drawable.school_backpack));
                lsFlashcard.add(new Flashcard(2, getString(R.string.school_textbook), R.drawable.school_textbook));
                lsFlashcard.add(new Flashcard(3, getString(R.string.school_book), R.drawable.school_book));
                lsFlashcard.add(new Flashcard(4, getString(R.string.school_workbook), R.drawable.school_workbook));
                lsFlashcard.add(new Flashcard(5, getString(R.string.school_file), R.drawable.school_file));
            }
            else if(number == 2){
                lsFlashcard.add(new Flashcard(1, getString(R.string.school_backpack), R.drawable.school_backpack));
                lsFlashcard.add(new Flashcard(2, getString(R.string.school_textbook), R.drawable.school_textbook));
                lsFlashcard.add(new Flashcard(3, getString(R.string.school_book), R.drawable.school_book));
                lsFlashcard.add(new Flashcard(4, getString(R.string.school_workbook), R.drawable.school_workbook));
                lsFlashcard.add(new Flashcard(5, getString(R.string.school_file), R.drawable.school_file));
            }
            else{
                lsFlashcard.add(new Flashcard(1, getString(R.string.school_backpack), R.drawable.school_backpack));
                lsFlashcard.add(new Flashcard(2, getString(R.string.school_textbook), R.drawable.school_textbook));
                lsFlashcard.add(new Flashcard(3, getString(R.string.school_book), R.drawable.school_book));
                lsFlashcard.add(new Flashcard(4, getString(R.string.school_workbook), R.drawable.school_workbook));
                lsFlashcard.add(new Flashcard(5, getString(R.string.school_file), R.drawable.school_file));
            }
        }
    }
    else{

    }

    View v = inflater.inflate(R.layout.fragment_flashcard, container, false);
    RecyclerView myRv = (RecyclerView) v.findViewById(R.id.main_recyclerView);
    FlashcardRecyclerViewAdapter myAdapter = new FlashcardRecyclerViewAdapter(getActivity(), lsFlashcard);
    myRv.setLayoutManager(new GridLayoutManager(getActivity(), 3));
    myRv.setAdapter(myAdapter);
    return v;
}
</code></pre>

<p>}</p>

<p>The error I'm getting is:</p>

<p>java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference</p>
