-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?

2
  • Why not change your getAllJamky function to return the proper type instead? Commented Jan 22, 2017 at 23:32
  • The solution that I found was really simple. I just changed private ArrayList<Jamky> campojamkyList to private List<Jamky> campojamkyList and it is working. Commented Jan 23, 2017 at 19:10

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I am doing, but the problem was the declaration of the list.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.