I am trying to get all the courses from user device, and show them on screen

I am trying to achieve the functionality of getting the courses from the Garmin devices and whenever any course is clicked the navigation should start with a corresponding course

until now what I've done is, that the application always crashes, and menu item did not get inflated any help will be highly appreciated,

try {
var iterator = PersistedContent.getCourses;
for (var i = 0; i < iterator.size(); i++) {
var content = iterator.next(); // Get the next object in the iterator
menu.addItem(
new MenuItem(
content.getName(),
"",
content.getId(), {}
)
);
}
} catch (exception) {
System.println("catch: " + exception);
} finally {
System.println("finally");
}