0

I have this fragment:

public class ResultFragment extends Fragment implements LoaderCallbacks{

public static ResultFragment newInstance(Bundle args) {
ResultFragment fragment = new ResultFragment();
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    getActivity().getSupportLoaderManager().initLoader(0, null, this);

}

@Override
public Loader<EstateSearch> onCreateLoader(int id, Bundle args) {

        return new RESTLoader(getActivity(), "http://etc");

}

@Override
public void onLoadFinished(Loader<EstateSearch> loader, EstateSearch es) {

}

@Override
public void onLoaderReset(Loader<EstateSearch> loader) {

}

}

The AsyncTaskLoader looks like this:

public class RESTLoader extends AsyncTaskLoader {

private String searchUrl; 

public RESTLoader(Context context, String searchUrl) {
    super(context);
    this.searchUrl = searchUrl; 


}

@Override
public EstateSearch loadInBackground() {


      EstateSearch es = null;       

      try {


    Network Stuff


    } catch (Exception e) {

    }

      return es; 
}

@Override
public void deliverResult(EstateSearch es) {


    super.deliverResult(es);
}

@Override
protected void onStartLoading() {
    forceLoad();
}

@Override
protected void onStopLoading() {

    cancelLoad();
}

@Override
protected void onReset() {
    super.onReset();        
    onStopLoading();     
}
}

The app crashes with a mysterious (at least to me) error:

http://i46.tinypic.com/260fw43.png

From putting in some Log.ds I know that the constructor of the AsyncTaskLoader isn't even called. I already tried to move the init() of the loader to later parts of the fragment lifecycle. The fragment is within a ViewPager btw if that's important. The AsyncTaskLoader works fine when called from an Activity.

Any ideas on what I'm doing wrong?

fweigl
  • 21,278
  • 20
  • 114
  • 205
  • The error might be in the snipped network stuff, you might want to check for casts and conversions. Probably you are casting an integer to a enum value, but this integer is outside the enum's range. – Machinarius Feb 08 '13 at 13:48
  • Thanks but no, the RESTLoader isnt even created with it's constructor, so it never does the network stuff. – fweigl Feb 08 '13 at 13:51

1 Answers1

0

Okay, pretty embarassing mistake: I already had another Loader in the Activity that the fragment is attached to which also had the ID 0 :-/

fweigl
  • 21,278
  • 20
  • 114
  • 205