Note that there are some explanatory texts on larger screens.

plurals
  1. POgetActivity() in ArrayAdapter sometimes returns null
    primarykey
    data
    text
    <p>I'm occasionally getting a <code>NullPointerException</code> in my ArrayAdapter that populates my ListFragment. It appears that <code>getActivity()</code> is returning null, but as far as I can tell it shouldn't do that.</p> <p>Adapter code <code>inflater = (LayoutInflater)...</code> is the exception line:</p> <pre><code>@Override public View getView( int position, View convertView, ViewGroup parent ) { view = convertView; if ( view == null ) { /* Inflate a row */ inflater = (LayoutInflater)getActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE ); // THIS IS THE EXCEPTION LINE view = inflater.inflate( R.layout.pairing_list_row, parent, false ); } </code></pre> <p>I'm using a Loader to get the data, and I don't init that until the <code>onActivityCreated</code> method. The adapter isn't created until the loader is finished loading, so it should never happen prior to <code>onActivityCreated</code>.</p> <pre><code>@Override public void onActivityCreated( Bundle savedInstanceState ) { super.onActivityCreated( savedInstanceState ); getLoaderManager().initLoader( 0, null, this ); } @Override public void onLoadFinished( Loader&lt;Cursor&gt; loader, Cursor cursor ) { PairingArrayAdapter pairings = (PairingArrayAdapter)getListAdapter(); if ( pairings == null ) { pairings = new PairingArrayAdapter( getActivity(), R.layout.pairing_list_row ); setListAdapter( pairings ); } ... </code></pre> <p>Any ideas on what's causing the NullPointerException? It doesn't happen all the time, it happens once, I do the same thing again and it doesn't happen. I can't figure it out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload