Skip to content

Tons of ProgressFragment.ensureContent errors #25

@Swisyn

Description

@Swisyn

Sometimes i get tons of error feedbacks from my users about the lib.

java.lang.IllegalStateException: Content view not yet created
at com.devspark.progressfragment.ProgressFragment.ensureContent(ProgressFragment.java:273)
at com.devspark.progressfragment.ProgressFragment.setContentEmpty(ProgressFragment.java:250)

My fragments like;
public class BusListFragment extends ProgressFragment {
private Context context;
private CardRecyclerView cardRecyclerView;
private View rootView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    setRetainInstance(true);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_mycards, container, false);
    context = getActivity();
    cardRecyclerView = (CardRecyclerView) rootView.findViewById(R.id.cardRecyclerView);
    return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setContentView(rootView);
    if (stopId != null && location != null) {
        new getClosestBusListAsync(this).execute();
    }
}

}
and the task is like;
public class getClosestStopListAsync extends AsyncTask<Void, Void, String> {
ProgressFragment fragment;
Context context;
GoogleMap map;
LatLng location;

public getClosestStopListAsync(ProgressFragment fragment, LatLng location, GoogleMap map) {
    this.fragment = fragment;
    this.context = fragment.getActivity();
    this.location = location;
    this.map = map;
}

@Override
protected String doInBackground(Void... args0) {
    return new RequestHelper().getClosestStopList(PreferenceHelper.getCity(context), location.latitude, location.longitude);
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
    if (result != null) {
        map.clear();

        BusStop stopList = JsonHelper.getClosestStopList(result);
        if (stopList != null) {
            if (stopList.getResult().getCode().equals("0")) {
                if (stopList != null || stopList.getBusStopList().size() > 0) {
                    for (BusStop.BusStopItem busStop : stopList.getBusStopList()) {
                        map.addMarker(new MarkerOptions()
                                .position(new LatLng(Double.parseDouble(busStop.getLatitude()), Double.parseDouble(busStop.getLongitude())))
                                .title(busStop.getStopId() + " - " + busStop.getStopName() + " - " + busStop.getType())
                                .snippet(busStop.getRoutes())
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.stop)));
                    }
                    fragment.setContentEmpty(false);
                } else {
                    fragment.setContentEmpty(true);
                    fragment.setEmptyText(R.string.empty_list);
                }
            }
        }
        System.gc();
        fragment.setContentShown(true);
    }
}

}

how can it be possible that content view not yet created? OnActivityCreated is called after OnCreateView so that means views could be created?

How can i fix this issue? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions