0

我有以下代码将自定义适配器添加到 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();
}

}

我究竟做错了什么?我的应用程序甚至没有启动就停止了:(

4

1 回答 1

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;
}
于 2013-06-22T18:26:28.907 回答