Buggy code:
public class HikeSearchFragment extends Fragment { private static final int MIN_TIME_INTERVAL_MS = 3000 ; private static final int MIN_DISTANCE_INTERVAL_M = 3 ; private View rootView ; private ListView hikeSearchListView ; private TextView noItemTextView ; private TaskListener getListHikeListener ; private TaskListener getSpecificHikeListener ; private LocationManager locManager ; private HikeSearchFragment . GetCurrentLocationListener locListener ; private LatLng currentLocation ; Context context ; @ Override public View onCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) { rootView = inflater . inflate ( fragment_hike_search , container , false ) ; hikeSearchListView = ( ( ListView ) ( rootView . findViewById ( hike_search_list ) ) ) ; noItemTextView = ( ( TextView ) ( rootView . findViewById ( tv_no_item ) ) ) ; context = getActivity ( ) ; getListHikeListener = new TaskListener ( ) { @ Override public void onSuccess ( String content ) { System . out . println ( content ) ; List < Hike > hikes = new ArrayList < Hike > ( ) ; try { JSONObject hikesList = new JSONObject ( content ) ; JSONArray hikesArray = hikesList . getJSONArray ( JSON_OBJECT ) ; for ( int i = 0 ; i < ( hikesArray . length ( ) ) ; i ++ ) { JSONObject hike = hikesArray . getJSONObject ( i ) ; hikes . add ( new Hike ( hike . getString ( JSON_HIKE_NAME ) , hike . getString ( JSON_HIKE_ID ) , hike . getString ( JSON_HIKE_DURATION ) , ( ( float ) ( hike . getDouble ( JSON_HIKE_LENGTH ) ) ) ) ) ; } } catch ( JSONException e ) { e . printStackTrace ( ) ; } <START_BUG> if ( ( hikes . size ( ) ) == 0 ) { <END_BUG> hikeSearchListView . setVisibility ( VISIBLE ) ; noItemTextView . setVisibility ( GONE ) ; HikeSearchFragment . HikeListAdapter customAdapter = new HikeSearchFragment . HikeListAdapter ( context , layout . search_list_item , hikes ) ; hikeSearchListView . setAdapter ( customAdapter ) ; } } @ Override public void onFailure ( ErrorCode errCode ) { if ( errCode == ( ErrorCode . REQUEST_FAILED ) ) { Toast . makeText ( context , request_failed , LENGTH_SHORT ) . show ( ) ; } else if ( errCode == ( ErrorCode . FAILED ) ) { Toast . makeText ( context , fail_retrieving_hikes , LENGTH_SHORT ) . show ( ) ; } } } ; getSpecificHikeListener = new TaskListener ( ) { @ Override public void onSuccess ( String content ) { try { System . out . println ( content ) ; JSONObject restultJSON = new JSONObject ( content ) ; JSONObject specificHike = restultJSON . getJSONObject ( JSON_OBJECT ) ; JSONArray JSONCoordinates = specificHike . getJSONArray ( PARAMETER_COORDINATES ) ; List < LatLng > coordinates = parseCoordinates ( JSONCoordinates ) ; Hike hikeToConsult = new Hike ( specificHike . getString ( JSON_HIKE_NAME ) , coordinates , ( ( float ) ( specificHike . getDouble ( JSON_HIKE_LENGTH ) ) ) , specificHike . getString ( JSON_HIKE_DURATION ) , ( ( float ) ( specificHike . getDouble ( JSON_HIKE_POSITIVE_HEIGHT_DIFF ) ) ) , ( ( float ) ( specificHike . getDouble ( JSON_HIKE_NEGATIVE_HEIGHT_DIFF ) ) ) , ( ( float ) ( specificHike . getDouble ( PARAMETER_AVERAGE_SPEED ) ) ) , specificHike . getString ( JSON_HIKE_DATE ) ) ; Intent intent = new Intent ( context , ConsultingHikeActivity . class ) ; intent . putExtra ( EXTRA_HIKE , hikeToConsult ) ; startActivity ( intent ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; } } @ Override public void onFailure ( ErrorCode errCode ) { if ( errCode == ( ErrorCode . REQUEST_FAILED ) ) { Toast . makeText ( context , request_failed , LENGTH_SHORT ) . show ( ) ; } else if ( errCode == ( ErrorCode . FAILED ) ) { Toast . makeText ( context , request_failed , LENGTH_SHORT ) . show ( ) ; } } } ; locManager = ( ( LocationManager ) ( getActivity ( ) . getSystemService ( LOCATION_SERVICE ) ) ) ; locListener = new HikeSearchFragment . GetCurrentLocationListener ( ) ; PackageManager pm = getActivity ( ) . getPackageManager ( ) ; boolean hasGps = pm . hasSystemFeature ( FEATURE_LOCATION_GPS ) ; if ( ! hasGps ) { locManager . requestLocationUpdates ( NETWORK_PROVIDER , HikeSearchFragment . MIN_TIME_INTERVAL_MS , HikeSearchFragment . MIN_DISTANCE_INTERVAL_M , locListener ) ; } else if ( hasGps && ( ! ( locManager . isProviderEnabled ( GPS_PROVIDER ) ) ) ) { HikeServices . getHikesShared ( getListHikeListener ) ; } else { locManager . requestLocationUpdates ( GPS_PROVIDER , HikeSearchFragment . MIN_TIME_INTERVAL_MS , HikeSearchFragment . MIN_DISTANCE_INTERVAL_M , locListener ) ; } hikeSearchListView . setOnItemClickListener ( new OnItemClickListener ( ) { public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) { Hike hike = ( ( Hike ) ( parent . getAdapter ( ) . getItem ( position ) ) ) ; HikeServices . getSpecificHike ( hike . getId ( ) , getSpecificHikeListener ) ; } } ) ; return rootView ; } @ Override public void onDestroyView ( ) { } public class HikeListAdapter extends ArrayAdapter < Hike > { public HikeListAdapter ( Context context , int textViewResourceId ) { } public HikeListAdapter ( Context context , int resource , List < Hike > items ) { } @ Override public View getView ( int position , View convertView , ViewGroup parent ) { } } public class GetCurrentLocationListener implements LocationListener { @ Override public void onLocationChanged ( Location location ) { } @ Override public void onProviderDisabled ( String provider ) { } @ Override public void onProviderEnabled ( String provider ) { } @ Override public void onStatusChanged ( String provider , int status , Bundle extras ) { } } }

Fix:
if ( ( hikes . size ( ) ) > 0 ) {