# Facing problem while using Event API

**URL:** <https://forum.asana.com/t/facing-problem-while-using-event-api/24834>\
**Category:** API & Developers\
**Created:** [23 June 2018 10:49 UTC](https://forum.asana.com/t/facing-problem-while-using-event-api/24834 "2018-06-23T10:49:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuldeep\_Poonia](https://luna1.co/8d76cd.png) [@Kuldeep\_Poonia](https://forum.asana.com/u/Kuldeep_Poonia)\
**Post date:** [23 June 2018 10:49 UTC](https://forum.asana.com/t/facing-problem-while-using-event-api/24834/1 "2018-06-23T10:49:48Z")

</div>

Hi All,

I am using event api with java platform and capturing all event for a project. But after 10 -20 minutes later it always shows me error

Exception in thread “Thread-7” java.util.NoSuchElementException  
at com.asana.iterator.PageIterator.next(PageIterator.java:54)  
at com.asana.iterator.EventsPageIterator.next(EventsPageIterator.java:42)  
at com.asana.iterator.ItemIterator.next(ItemIterator.java:25)

or sometime it shows

Exception in thread “Thread-11” com.google.gson.JsonIOException: java.net.SocketTimeoutException: Read timed out  
at com.google.gson.Gson.assertFullConsumption(Gson.java:788)  
at com.google.gson.Gson.fromJson(Gson.java:776)  
at com.asana.requests.ItemRequest.executeRaw(ItemRequest.java:39)  
at com.asana.requests.ItemRequest.execute(ItemRequest.java:27)

here is my code:

```
EventsRequest<Event> request = client.events.get(projectId);
for (Iterator<Event> iterator = request.iterator(); iterator.hasNext();) {
    Event e = (Event) iterator.next();
    String action = e.action;
    String type = e.type;
}

```

Can anyone tell me the solution?

---

<div class="post-metadata">

**Author:** ![Matt\_Bramlage](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/matt_bramlage/32/145_2.png) [@Matt\_Bramlage](https://forum.asana.com/u/Matt_Bramlage)\
**Post date:** [2 July 2018 21:59 UTC](https://forum.asana.com/t/facing-problem-while-using-event-api/24834/2 "2018-07-02T21:59:11Z")

</div>

Hey there @Kuldeep_Poonia,

The second error is simply a timeout error - trying to read the response, but the request took too long. I believe we’re supposed to retry in this case, but it doesn’t appear that we do. I’ll file an enhancement request in Asana.

I’'m not sure about the first error - calling `next()` will throw `NoSuchElementException` if there isn’t another element, but it should be checking with every loop. One brute force method might be to simply break out of the loop as if `hasNext()` were false in this case, but without being able to sit down and reproduce/debug, I think this will be tricky to track down. Is your app multi-threaded? Is it possible that there’s a race condition where you’re calling `next()` in a separate thread (or otherwise consuming the event from Asana with a different event stream) that might set up a race condition where `hasNext()` is true, but the event is consumed somewhere else becore `next()` is called? 🤔

---

<div class="post-metadata">

**Author:** ![danelyoung](https://luna1.co/8d76cd.png) [@danelyoung](https://forum.asana.com/u/danelyoung)\
**Post date:** [25 May 2020 08:02 UTC](https://forum.asana.com/t/facing-problem-while-using-event-api/24834/3 "2020-05-25T08:02:24Z")

</div>

The NoSuchElementException in Java is thrown when one tries to access an iterable beyond its maximum limit. This means that, this exception is thrown by various accessor methods to indicate that the element being requested does not exist . The next() method in Java returns the next element in the iteration or [NoSuchElementException](http://net-informations.com/java/err/elements.htm) if the iteration has no more elements.

As with most programming languages, the Iterator class includes a hasNext() method that returns a boolean indicating if the iteration has anymore elements. If hasNext() returns true, then the next() method will return the next element in the iteration otherwise raise exceptions if the iteration has no more elements.

```
if(input.hasNextInt() )
     number1 = input.nextInt(); // if there is another number  
else 
     number1 = 0; // nothing added in the input

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 19:06 UTC](https://forum.asana.com/t/facing-problem-while-using-event-api/24834/4 "2025-05-30T19:06:51Z")

</div>

Closed on 30 May 2025 19:06 UTC


