java.lang.ClassCastException: cannot be cast to java.lang.Long
<blockquote>
  <p>Blockquote</p>
</blockquote>

<p>I am trying to Iterate List of Long objects and setting each value into long variable.But i am getting </p>

<blockquote>
  <p>java.lang.ClassCastException :: cannot be cast to java.lang.Long</p>
</blockquote>

<p>How can I get solve this issue?</p>

<pre><code>List&lt;Long&gt; listLong = new ArrayList&lt;Long&gt;();
listLong = SampleService.sampleList();

for(int i=0;i&lt;listLong.size();i++){
    long sampleId = listLong.get(i).longValue();
}
</code></pre>

<p>`</p>

<pre><code>public List&lt;Long&gt; sampleList() throws Exception{

    LOGGER.info("start of sampleList method ");
    List&lt;Long&gt; sampList = null;
    final MapSqlParameterSource params = new MapSqlParameterSource();

    final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
            .withProcedureName("SAMPLE_TERM");
    simpleJdbcCall.declareParameters(new SqlOutParameter("SAMPLE_CURSER",
            OracleTypes.CURSOR, new SampleRowMapper()));

    final Map&lt;String, Object&gt; out = simpleJdbcCall.execute(params);

    sampList = (List&lt;Long&gt;) out.get("SAMPLE_CURSER");
    LOGGER.debug("List  :: "+sampList .size());

    return sampList ;

}
</code></pre>

<blockquote>
  <p></p>
</blockquote>

<pre><code>java.lang.ClassCastException: com.sample cannot be cast to java.lang.Long
        at com.sample.cronTask(sample.java:49)
        at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
</code></pre>