0
我在MainActivity中使用三個片段。Android內容視圖尚未創建
它來自fata例外:main。說, 的RequestFragment.class線54是例外的原因:
adapter = new RequestAdapter(getListView().getContext(), mRequests);
的RequestAdapter是separatedly implementated類。
謝謝! 代碼:
@Override
public void onResume() {
super.onResume();
getActivity().setProgressBarIndeterminateVisibility(true);
currentUserName = ParseUser.getCurrentUser().getUsername();
getActivity().setProgressBarIndeterminate(true);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_ACTIVITYREQUEST);
query.whereEqualTo(ParseConstants.KEY_RECIPIENTNAME, currentUserName);
//Reorder the result according to the time users shake the phone
query.addDescendingOrder(ParseConstants.KEY_CREATEDAT);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> requests, ParseException e) {
getActivity().setProgressBarIndeterminateVisibility(false);
if(e == null){
mRequests = requests;
adapter = new RequestAdapter(getListView().getContext(), mRequests);
setListAdapter(adapter);
}
else{
Log.d(TAG, "no request");
}
}
});
}
而不是使用getListView()的getContext()u可以使用,getActivity()。 – r4jiv007