0

I'm getting this message while building my project:

...\listadapter\MyAdapter.java:

uses unchecked or unsafe operations.

Recompile with -Xlint:unchecked for details.

This happens for this lines of code:

@Override
    protected void publishResults(CharSequence constraint, FilterResults results) {
        beanList = (ArrayList<Bean>) results.values;
        notifyDataSetChanged();
    }

I have no clue what to do.

Web.11
  • 406
  • 2
  • 8
  • 23

2 Answers2

1

You can try to use a try catch method catching an Excepcion or you can create a new Excepion for this problem, for it you can create a class which extends Exception, you can read more about it here: How to creat a custom Exception.

Gui Gobin
  • 13
  • 5
1

That's because you are casting to a generic type, and the compiler don't know if this casting is legal. If your results.values isn't an instance of ArrayList, this line of code will fail with a ClastCastException. But if it is, compiler will cast the value, but it can't check what the type of generic parameter is, and if your variable holds ArrayList with strings inside, your line of code won't fail, but it will at another one, where you are reading from the list. If you are 100% sure it will be an ArrayList of Bean you can just suppress this warning (by annotating the method with @SuppressWarnings("unchecked")

Andrey Antipov
  • 370
  • 3
  • 9
  • it is always list of beans, apps works great, but when I compile I get that warring. So I added @SupressWarnings("unchecked"). – Web.11 Mar 01 '19 at 19:50
  • 1
    Try SuppressWarnings, not SupressWarnings. That will teach me to copy and paste from SO answers. – iforce2d May 04 '20 at 10:41