@@ -269,26 +269,27 @@ private void adjustCategorySpinner(int catID) {
269269
270270 // loop over all categories to find the position for the current
271271 // category id
272- cursorAllCat .moveToFirst ();
273- int position = 1 ;
274- do {
275- if (cursorAllCat .getInt (0 ) == catID )
276- break ;
277-
278- cursorAllCat .moveToNext ();
279- position ++;
280- } while (!cursorAllCat .isLast ());
281-
282- String [] columns = new String [] { CategoriesTable .CATEGORIES_KEY_NAME };
283- int [] to = new int [] { android .R .id .text1 };
284-
285- SimpleCursorAdapter mAdapter = new SimpleCursorAdapter (this .getActivity (),
286- android .R .layout .simple_spinner_item , cursorAllCat , columns , to );
287-
288- mAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
289- categorySpinner .setAdapter (mAdapter );
290-
291- categorySpinner .setSelection (position - 1 );
272+ if (cursorAllCat .getCount () > 0 ) {
273+ cursorAllCat .moveToFirst ();
274+ int position = 1 ;
275+ do {
276+ if (cursorAllCat .getInt (0 ) == catID )
277+ break ;
278+
279+ cursorAllCat .moveToNext ();
280+ position ++;
281+ } while (!cursorAllCat .isLast ());
282+
283+ String [] columns = new String [] { CategoriesTable .CATEGORIES_KEY_NAME };
284+ int [] to = new int [] { android .R .id .text1 };
285+
286+ SimpleCursorAdapter mAdapter = new SimpleCursorAdapter (this .getActivity (),
287+ android .R .layout .simple_spinner_item , cursorAllCat , columns , to );
288+
289+ mAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
290+ categorySpinner .setAdapter (mAdapter );
291+ categorySpinner .setSelection (position - 1 );
292+ }
292293 }
293294
294295 private Cursor getCategoriesCursor () {
0 commit comments