westnordost / osmapi-overpass

Java client for the Overpass API
GNU Lesser General Public License v3.0
17 stars 0 forks source link

From where does the "handler" come from? #2

Closed KerryKilian closed 3 years ago

KerryKilian commented 3 years ago

Android studio does not know the "handler". How can I initilize it?

westnordost commented 3 years ago

The handler is the interface you implement yourself.

KerryKilian commented 3 years ago

Is it the class or the map or something else? Maybe you can give an example?

westnordost commented 3 years ago

For example


int nodes = 0;
int ways = 0;
int relations = 0;

overpassMapDataDao.queryElements("[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out meta;", new MapDataHandler() {
  public void handle(BoundingBox bounds) {
    // a bounding box was parsed from the overpass response, do something with it or not
  }

  public void handle(Node node) {
    // a node was parsed from the overpass response, do something with it or not
    nodes++;
  }

  public void handle(Way way) {
    // a way was parsed from the overpass response, do something with it or not
    ways++;
  }

  public void handle(Relation relation) {
    // a relation was parsed from the overpass response, do something with it or not
    relations++;
  }
});
System.out.println("On Malta, there are " (nodes+ways+relations) + " shops, of these: " + nodes + " nodes, " + ways + " ways and " + relations + " relations");
KerryKilian commented 3 years ago

I get this error (and much more lines similar to that): Duplicate class org.jetbrains.annotations.Async$Execute found in modules jetified-annotations-16.0.1 (org.jetbrains:annotations:16.0.1) and jetified-annotations-java5-18.0 (org.jetbrains:annotations-java5:18.0.0) Thanks by the way for your help:)

westnordost commented 3 years ago

Hm I don't remember what was the solution to it. The annotations used in this library collide with the annotations used in Android. In the gradle config, you can exclude certain dependencies to remove the duplicates. I am too busy so I can't help you now, try searching for the problem with google. When you found the solution, please let me know, then I can update the readme.

KerryKilian commented 3 years ago

In build.gradle under android { } I added configurations { cleanedAnnotations compile.exclude group: 'org.jetbrains' , module:'annotations' all*.exclude group: 'xmlpull', module: 'xmlpull' } The error disappears and my app is starting but crashes right after start. Now I have to figure out if these above lines caused the crash or something else in my code EDIT: Your example code from above causes the crash