1

I have this function makeAirportManagers() which should return an ArrayList <MarkerManager> all required variables map, countryMarkers and airportMarkers are global (dirty processing style).

ArrayList  makeAirportManagers(){
  ArrayList  managers = new ArrayList();
  for (Marker country : countryMarkers){
    MarkerManager currentMarkerManager = new MarkerManager();
    for (Marker airport : airportMarkers){
      Location airportLocation = airport.getLocation();
      ScreenPosition airportScreenPos = map.getScreenPosition(airportLocation);
      if(country.isInside(map, airportScreenPos.x, airportScreenPos.y)){
        currentMarkerManager.addMarker(airport);
      }
    }
    currentMarkerManager.disableDrawing();
    managers.add(currentMarkerManager);
    map.addMarkerManager(currentMarkerManager);
    airportManagersBuild = true;
    return managers;
  }
}

The console prints: This method must return a result of Type ArrayList

And really I don't no why!

In another version of the code, I count the items of managersto make sure it`s not empty and it gets 178 items like expected.

I am using Processing 1.5.1 because of the Unfolding library I'm playing with.

2 Answers 2

3

Your return method is inside the for loop. You must move it one line below.

Sign up to request clarification or add additional context in comments.

1 Comment

I am so blind! Thank you very much!
1

If countryMarkers has no element in it, you will never reach the line return managers and your method won't return anything.

Even if you know that your container will never be empty, the Java compiler does not. Thus your error.

2 Comments

Thank you, but countryMarkers is not empty.
You know that. Not your compiler. Your compiler is righter than you or me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.