我有以下代码将自定义适配器添加到listView,但它在我设置适配器的行上给出以下错误:
android.content.res.Resources $ NotFoundException:字符串资源ID#0x68
public class PackageListFragment extends Fragment {
PackageAdapter packageItemAdapter;
ArrayList<PackageClass> list;
PackageClass packageList;
TextView mainLine;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_aps__main, container, false);
ListView lv = (ListView) rootView.findViewById(R.id.packageList);
try{
list = getAllPackages();
packageItemAdapter = new PackageAdapter(getActivity().getApplicationContext(), 0, list);
lv.setAdapter(packageItemAdapter);
}
}
catch(Exception ex){
Log.e("listItem", ex.toString());
}
return rootView;
}
public ArrayList<PackageClass> getAllPackages() throws Exception{
return new DBFunctions(getActivity().getApplicationContext()).RetrieveAllPackage();
}
}
我做错了什么?我的应用程序甚至没有启动就停止了:(
答案 0 :(得分:0)
修改完问题后,我注意到try
/ catch
块中的一个括号似乎有误。我将您的代码复制到此答案中,并评论了可能有问题的括号。但这可能只是问题的错误,而不是你的代码,因为我不相信它会编译出这个问题。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_aps__main, container, false);
ListView lv = (ListView) rootView.findViewById(R.id.packageList);
try{
list = getAllPackages();
packageItemAdapter = new PackageAdapter(getActivity().getApplicationContext(), 0, list);
lv.setAdapter(packageItemAdapter);
}
} // <---- seems out of place
catch(Exception ex){
Log.e("listItem", ex.toString());
}
return rootView;
}