Buggy code:
public class HikeListFragment extends Fragment { View rootView ; ListView hikesListView ; TextView noItemTextView ; Context context ; TaskListener getSpecificHikeListener ; TaskListener getListHikeListener ; @ Override public View onCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) { rootView = inflater . inflate ( fragment_hike_list , container , false ) ; hikesListView = ( ( ListView ) ( rootView . findViewById ( my_hike_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 ) ) ) , ( ( float ) ( hike . getDouble ( PARAMETER_AVERAGE_SPEED ) ) ) ) ) ; } } catch ( JSONException e ) { e . printStackTrace ( ) ; } <START_BUG> if ( ( hikes . size ( ) ) == 0 ) { <END_BUG> hikesListView . setVisibility ( VISIBLE ) ; noItemTextView . setVisibility ( GONE ) ; HikeListFragment . HikeListAdapter customAdapter = new HikeListFragment . HikeListAdapter ( context , layout . hike_list_item , hikes ) ; hikesListView . setAdapter ( customAdapter ) ; hikesListView . 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 ) ; } } ) ; } } @ 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 ( ) ; } } } ; HikeServices . getMyHikes ( getListHikeListener ) ; return rootView ; } 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 ) { } } }

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