gpt4 book ai didi

java.lang.IllegalStateException : Content view not yet created while using drawer

转载 作者:太空宇宙 更新时间:2023-11-04 14:19:28 24 4
gpt4 key购买 nike

我正在为我的 Android 应用程序使用抽屉列表。有问题。当我随机单击(非常快)时,我会得到强制停止和 java.lang.IllegalStateException: Content view not yet created显示在日志中。我正在使用 fragment

我还收到以下运行时错误在 android.support.v4.app.ListFragment.ensureList(ListFragment.java:32

这是我的代码的一部分,用于从抽屉列表中进行选择,

Fragment home = new Home();
Fragment feeds = new Feeds_ListView();

...

private void selectItem(int position) 
{

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
switch (position)
{

case 0:
setTitle(title[position]);
ft.replace(R.id.content_frame, feeds);

break;
case 1:
setTitle(title[position]);
ft.replace(R.id.content_frame, NewPostFragment);
break;
case 2:
setTitle(title[position]);
ft.replace(R.id.content_frame, SearchDetailsFragment);
break;
case 3:
setTitle(title[position]);
ft.replace(R.id.content_frame, feeds1);
break;
case 4:
setTitle(title[position]);
ft.replace(R.id.content_frame, UserDetailsFragment);
break;
case 5:
setTitle(title[position]);
ft.replace(R.id.content_frame, FBActivity);
break;
}
ft.commit();
mDrawerList.setItemChecked(position, true);
setTitle(title[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}


@Override
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

@Override
public void setTitle(CharSequence title)
{
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}

这是Feeds_ListView()的部分;

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
context=container.getContext();
rootView = inflater.inflate(R.layout.feeds_listview_layout, container, false);


list = (ListView) rootView.findViewById(android.R.id.list);
mRelativeLayout=rootView.findViewById(R.id.mRelativeLayout);

saveProgress =(ProgressBar) rootView.findViewById(R.id.loadpost);
saveProgress.setVisibility(View.INVISIBLE);



userAdapter = new CustomListAdapter(getActivity(), R.layout.feeds_listview_item,userArray);





mRelativeLayout.setVisibility(View.GONE);

list.setItemsCanFocus(false);
list.setAdapter(userAdapter);
return rootView;

}





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

SharedPreferences settings =getActivity().getSharedPreferences("newdatabase",0);

String user_id=settings.getString("user_id", "--");

if(user_id.equals("--") || user_id.equals(""))
{ FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();

ft.replace(R.id.content_frame, FBActivity);
ft.commit();
}else{
new Onscrollasync().execute();

((PullToRefresh_Master) getListView()).setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
new Onscrollasync().execute();
}
});
}


}

最佳答案

问题出在您在 onCreateView 中编写的 Fragment Home 中的代码。将 onCreateView() 中的代码移至 onActivityCreated()onViewCreated()。 StackOverlflow 上有几个类似的问题,例如 here .

关于java.lang.IllegalStateException : Content view not yet created while using drawer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27353228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com