NullPointerException in RecyclerAdapter
<p><strong>Update:</strong> The problem was due to initializing my RecyclerView twice, once globally and another time locally. This caused a NullPointerException due to the fact that the unassigned RecyclerView was being used for my data adapter.</p>

<p>I get a NullPointerException whenever I launch my app. Please don't mark this is a duplicate as I don't think it's exactly a NullPointerException problem as opposed to an issue with how my methods are structured.</p>

<p>My <strong>onCreate()</strong> has a method called <code>initialise()</code>, which separates the initialization of the adapter from launch and refresh:</p>

<pre><code>private boolean initialise() {
        boolean isOnline = NetworkHelper.isOnline(this);

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setHasFixedSize(true);
        retrieveYeets();

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
        mSwipeRefreshLayout.setOnRefreshListener(() -&gt; {
            if (!isOnline) {
                mSwipeRefreshLayout.setRefreshing(false);
            } else {

                retrieveYeets();

            }
        });
        return isOnline;
    }
</code></pre>

<p>The following method completes the adapter creation:</p>

<pre><code>private void retrieveYeets() {
        String groupId = ParseUser.getCurrentUser().getString("groupId");
        ParseQuery&lt;ParseObject&gt; query = new ParseQuery&lt;&gt;(ParseConstants.CLASS_MESSAGE);
        query.whereContains(ParseConstants.KEY_GROUP_ID, groupId);
        query.orderByDescending("lastReplyUpdatedAt");
        query.setLimit(1000);
        query.findInBackground((yeets, e) -&gt; {

            if (mSwipeRefreshLayout.isRefreshing()) {
                mSwipeRefreshLayout.setRefreshing(false);
            }

            if (e == null) {

                // We found messages!
                mYeets = yeets;
                System.out.println(yeets);
                FeedAdapter adapter = new FeedAdapter(getApplicationContext(), yeets);
                adapter.setHasStableIds(true);
                recyclerView.setAdapter(adapter);

            }
        });
    }
</code></pre>

<p>As you can see, I can print out my list and it is <strong>not null</strong>. I then feed my list into my adapter. Shouldn't this just work? Why the exception?</p>

<p><strong>Exception:</strong></p>

<pre><code>java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
      at com.yitter.feed.FeedAdapter.getItemCount(FeedAdapter.java:466)
      at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3170)
</code></pre>

<p><strong>Adapter:</strong></p>

<p>The class is quite large but the relevant parts are easy to digest, i.e. you can search <strong>onCreateViewHolder</strong>, <strong>onBindViewHolder</strong>, so I've provided a Gist:</p>

<p>Gist: <a href="https://gist.github.com/santafebound/70a82fb9a3349930a030ef66b426a04b" rel="nofollow">https://gist.github.com/santafebound/70a82fb9a3349930a030ef66b426a04b</a></p>