Queue Iterator with Java

I'm trying to use a queue to store a set amount of data and I want to be able to iterate through it. I made a new queue with a specific type and I am having a problem with the iterator. Whenever I call iterator.next() I have a type mismatch. "Can't convert from void to motionEvent". motionEvent is the type that I am storing. Any help would be much appreciated. Here is snippet of the code.

    Queue<motionEvent> queue = new LinkedList<motionEvent>();


    Iterator it = (Iterator) queue.iterator();

    for(int i = 0; i < 5; i++)
        motionEvent temp = it.next();
     //THis is where I am having the problem with mismatch type


Here is the motionEvent Class:

public class motionEvent
private long time;
private int positionX;
private int positionY;

public motionEvent()
    time = 0;
    positionX = 0;
    positionY = 0;

public motionEvent(long time_in, int positionX_in, int positionY_in)
    time = time_in;

    positionX = positionX_in;
    positionY = positionY_in;

public long getTime()
    return time;

public int[] getPosition()
    int[] temp = new int[]{positionX, positionY};
    return temp;



You should not cast to the raw type:

Iterator<MotionEvent> it = queue.iterator();

Well normally items of different type cannot be directly assigned by one to another. Also voids cannot be assigned, try finding the methods of iteration. Also your motionEvent is of its own type so it must be added indirectly threw a set or convertion.

Need Your Help

Storing points from a path objects on a ArrayList Android

java android arraylist path add

I have manage to draw a rectangle using the path object but I have problems adding the points into a point ArrayList. The x and y depends on the touch coordinates.

NoClassDeffoundError in spring android

android spring noclassdeffounderror

Hi guys I am facing problrm as NoClassDeffound: org.springframework.web.client.RestTemplate.