5

I'm trying to sort an ArrayList in my Android app, but its throwing an exception. Here's the part of my code where it happens:

List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);  
Collections.sort(packs);

Does anybody have any ideas?

3
  • 1
    What kind of error? Post your logcat
    – Egor
    Jul 19, 2011 at 6:58
  • 1
    Show us the error or exception you're getting.
    – Flo
    Jul 19, 2011 at 6:58
  • Have you try to use in-built sort function? Dec 14, 2011 at 10:31

3 Answers 3

3

packs contains PackageInfo objects, and sort can not find a natural order for those is my best guess. If you want to sort, use a Comparator with the sort which defines what you want to sort the PackageInfo objects on.

2

sorting
another example
one more
this also
may above link helpful to you Happy Coding..:):) thanks Pragna

2

here is a simple example of How to sort array in android?.

String[] array = new String[]{"one","two","three","four"};
Arrays.sort(array);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.