Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android非法状态异常内容视图尚未创建?_Android_Parse Platform_Android Listfragment - Fatal编程技术网

android非法状态异常内容视图尚未创建?

android非法状态异常内容视图尚未创建?,android,parse-platform,android-listfragment,Android,Parse Platform,Android Listfragment,嗨,当我启动抽屉活动片段时,会弹出“非法状态异常内容视图尚未创建”错误。这是我的代码和错误。我正在使用自定义列表适配器 错误: 10-14 09:40:25.926: E/AndroidRuntime(6736): java.lang.IllegalStateException: Content view not yet created 10-14 09:40:25.926: E/AndroidRuntime(6736): at android.app.ListFragment.ensu

嗨,当我启动抽屉活动片段时,会弹出“非法状态异常内容视图尚未创建”错误。这是我的代码和错误。我正在使用自定义列表适配器

错误:

10-14 09:40:25.926: E/AndroidRuntime(6736): java.lang.IllegalStateException: Content view not yet created
10-14 09:40:25.926: E/AndroidRuntime(6736):     at android.app.ListFragment.ensureList(ListFragment.java:386)
10-14 09:40:25.926: E/AndroidRuntime(6736):     at android.app.ListFragment.getListView(ListFragment.java:280)
10-14 09:40:25.926: E/AndroidRuntime(6736):     at com.example.fragments.HomeFragment$1.done(HomeFragment.java:74)
我的oncreateview

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(
            R.layout.fragment_home, container, false);
    listview=(ListView) rootView.findViewById(android.R.id.list);
    return rootView;
}
在恢复时调用mysetlist适配器

@Override
public void onResume() {
    super.onResume();

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Shopinfo");
    query.findInBackground(new FindCallback<ParseObject>() {

        @Override
        public void done(List<ParseObject> Shopinfo, ParseException e) {
            // TODO Auto-generated method stub
            if(e==null){
                mShop=Shopinfo;
                String[] spots = new String[mShop.size()];
                int i = 0;
                for(ParseObject Shopinfos : mShop) {
                    spots[i] =  Shopinfos.getString(ParseConstants.KEY_SHOP_NAME);
                    i++;
                }

                if (getListView().getAdapter() == null) {
                    adapter=new ShopListAdapter(list.getContext(), mShop);
                    setListAdapter(adapter);
                }
                else {
                    ((ShopListAdapter)getListView().getAdapter()).refill(mShop);
                }

            }

        }
    });

}
@覆盖
恢复时公开作废(){
super.onResume();
ParseQuery=新的ParseQuery(“Shopinfo”);
findInBackground(新的FindCallback(){
@凌驾
公共作废完成(列出Shopinfo,Parsee){
//TODO自动生成的方法存根
如果(e==null){
mShop=Shopinfo;
String[]spots=新字符串[mShop.size()];
int i=0;
用于(ParseObject Shopinfos:mShop){
spots[i]=Shopinfos.getString(ParseConstants.KEY\u SHOP\u NAME);
i++;
}
if(getListView().getAdapter()==null){
adapter=newshoplistadapter(list.getContext(),mShop);
setListAdapter(适配器);
}
否则{
((ShopListAdapter)getListView().getAdapter()).refill(mShop);
}
}
}
});
}

将以下内容移动到
onActivityCreated()
方法或
onViewCreated()

@覆盖
已创建ActivityState上的公共无效(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
ParseQuery=新的ParseQuery(“Shopinfo”);
findInBackground(新的FindCallback(){
@凌驾
公共作废完成(列出Shopinfo,Parsee){
//TODO自动生成的方法存根
如果(e==null){
mShop=Shopinfo;
String[]spots=新字符串[mShop.size()];
int i=0;
用于(ParseObject Shopinfos:mShop){
spots[i]=Shopinfos.getString(ParseConstants.KEY\u SHOP\u NAME);
i++;
}
if(getListView().getAdapter()==null){
adapter=newshoplistadapter(list.getContext(),mShop);
setListAdapter(适配器);
}
否则{
((ShopListAdapter)getListView().getAdapter()).refill(mShop);
}
}
}
});
}

一个好的做法是将所有使用UI小部件的内容放在
方法的activitycreated()
方法中。

从where is
adapter=new ShopListAdapter(listview.getContext(),mShop)
设置列表适配器(适配器)被调用?尝试通过添加super.onCreateView(充气机、容器、savedInstanceState)来调用它们;在onCreateView部分中。我是否应该首先为片段创建视图?您应该在onCreateView()中这样做。
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Shopinfo");
    query.findInBackground(new FindCallback<ParseObject>() {

        @Override
        public void done(List<ParseObject> Shopinfo, ParseException e) {
            // TODO Auto-generated method stub
            if(e==null){
                mShop=Shopinfo;
                String[] spots = new String[mShop.size()];
                int i = 0;
                for(ParseObject Shopinfos : mShop) {
                    spots[i] =  Shopinfos.getString(ParseConstants.KEY_SHOP_NAME);
                    i++;
                }

                if (getListView().getAdapter() == null) {
                    adapter=new ShopListAdapter(list.getContext(), mShop);
                    setListAdapter(adapter);
                }
                else {
                    ((ShopListAdapter)getListView().getAdapter()).refill(mShop);
                }

            }

        }
    });
    }