我的listFragment中有此消息错误,我已尝试在其他主题中提出的有关同一问题的一些解决方案,但它仍然无法正常工作。我没有在第一次得到错误但是在片段之间进行了一些导航之后.. 这是错误:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.rajaapp.ui.InboxFragment$2$1.done(InboxFragment.java:136)
at com.rajaapp.ui.InboxFragment$2$1.done(InboxFragment.java:121)
at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:107)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
这是片段代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_inbox, container, false);
fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setItems(R.array.camera_choices,mDialogListener);
AlertDialog dialog = builder.create();
dialog.show();
}
});
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
mSwipeRefreshLayout.setColorSchemeResources(
R.color.swipeRefresh1,
R.color.swipeRefresh2,
R.color.swipeRefresh3,
R.color.swipeRefresh4
);
return rootView;
}
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mprogressBar = (ProgressBar) getView().findViewById(R.id.progressBar);
fab.attachToListView(getListView());
retrieveMessages();
}
private void retrieveMessages() {
mAbonnementsRelation = ParseUser.getCurrentUser().getRelation(ParseConstants.KEY_ABONNEMENTS_RELATION);
mAbonnementsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> abonnes, ParseException e) {
if(e==null){
int i = 0;
for (ParseUser abonne : abonnes) {
AbonnesIds.add(abonne.getObjectId());
i++;
}
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
query.whereContainedIn(ParseConstants.KEY_SENDER_ID, AbonnesIds);
query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
if (!mSwipeRefreshLayout.isRefreshing()) {
mprogressBar.setVisibility(View.VISIBLE);
}
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> messages, ParseException e) {
mprogressBar.setVisibility(View.INVISIBLE);
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}
if (e == null) {
mMessages = messages;
String[] usernames = new String[mMessages.size()];
int i = 0;
for (ParseObject message : mMessages) {
usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
i++;
}
if (getListView().getAdapter() == null) {
MessageAdapter adapter = new MessageAdapter(getListView().getContext()
, mMessages);
setListAdapter(adapter);
} else {
((MessageAdapter) getListView().getAdapter()).refill(mMessages);
((MessageAdapter) getListView().getAdapter()).notifyDataSetChanged();
}
}
}
});
}
else{
Log.e(TAG,e.getMessage());
}
}
});
}
此行发生错误:
if (getListView().getAdapter() == null) {
答案 0 :(得分:0)
View rootView = inflater.inflate(R.layout.fragment_inbox, container, false);
将容器替换为null。并将onActivityCreated上的所有代码移动到onCreateView