I have the following code to add a custom adapter to a listView but it gives the following error on the line where I set the adapter:
android.content.res.Resources$NotFoundException: String resource 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();
}
}
What am I doing wrong? My application stops without even starting :(
After editing your question, I notice one of your brackets in the try
/ catch
block seems wrong. I copied your code into this answer and commented the potentially offending bracket. But this may just be a mistake in the question and not your code, since I don't believe it would compile with this problem.
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.