-1

I have a strange error message when I want to use the result of a Server query and an offline SQLite request.

Error message in Android Studio:

Incompatible types:
Required: java.util.Array.list
Found: java.util.List

ArrayList is declared: private ArrayList<Jamky> campojamkyList; and assigned: campojamkyList = new ArrayList<>();

The array returned is in both cases the same:

campolist = {ArrayList@1235} size = 18
0 = {Jamky@1235 }
 campoid = 23
 delka = 330
.......

When I want to assign the result of the SqLite Query campolist = db.getAllJamky(campo); I get the error message.

Does anybody has a clue why this strange behaviour occurs or some hints how to maybe convert the util.list to an Array.list?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Peter
  • 33
  • 7
  • Why not change your getAllJamky function to return the proper type instead? – Gabe Sechan Jan 22 '17 at 23:32
  • The solution that I found was really simple. I just changed private ArrayList campojamkyList to private List campojamkyList and it is working. – Peter Jan 23 '17 at 19:10

1 Answers1

3

Because List is not a class it is an interface. ArrayList implements List.

For a method, you better use a List as a return so you not restricting the method for further usage (to a LinkedList for example).

So, you need to change db.getAllJamky(campo) to something like this:

public List<YourObject> getAllJamky(YourObject yourObject) {
  List<YourObject> list = new ArrayList<>();
  // the implementation
  ...
  return list;
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96