我有两个选项卡的片段,每个选项卡都有各自的片段。每个选项卡都有自己的列表,该列表是从服务器加载的。但是我的应用程序遇到了异常,例如
java.lang.RuntimeException:无法启动活动 ComponentInfo{com.oj.bs/com.oj.bs.ProjectFragActivity}:java.lang.IllegalStateException:尚未创建内容视图
我不明白问题出在哪里。谁能告诉我我做错了什么?
以下是我的片段类
public class ResidentialFragActivity extends SherlockListFragment implements ActionBar.TabListener{
ListView listview;
ListView resListviewId;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.residential_list);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle saved) {
View view = inflater.inflate(R.layout.residential_list,container, false);
resListviewId = (ListView)view.findViewById(R.id.resProjListView);
projectList = new ArrayList<HashMap<String,String>>();
new LoadProjects().execute();
ListView listview = getListView();
listview.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
Intent href = new Intent(getSherlockActivity(), ProjectDetailActivity.class);
String proj_id = ((TextView) view.findViewById(R.id.projectId)).getText().toString();
href.putExtra("proj_id", proj_id);
getSherlockActivity().startActivity(href);
}
});
if (container == null) {
return null;
}
return view;
}
public void onStart() {
super.onStart();
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.add(android.R.id.content,this,"residential");
ft.attach(this);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.detach(this);
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
//inner class for network operation
private class LoadProjects extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
..........
//get data from the latest server
String jsonpProjList = ResdProj.makeHttpReqToSrvr(projectUrl, "POST", projRes);
return null;
}
@Override
protected void onPostExecute(String result) {
getSherlockActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ListAdapter projAdapter = new SimpleAdapter(getSherlockActivity(),
projectList, R.layout.residential_list_item,
new String[] {PROJ_ID,PROJ_NAME}, new int[]
{R.id.projectId,R.id.projectName});
//updating the UI
setListAdapter(projAdapter);
}
});
}
}
提前感谢