Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6583507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:25:05+00:00 2026-05-25T16:25:05+00:00

When iterating on the same loop twice, I got an error: freemarker.template.SimpleSequence cannot be

  • 0

When iterating on the same loop twice, I got an error:

freemarker.template.SimpleSequence cannot be cast to java.util.List

First Loop

<#assign peopleMap = context.getpeopleMapByGender()>

<#foreach item in peopleMap["man"] > 
            ${item.first_name!"Unknown"} ${item.last_name!"Unknown"} 
</#foreach>

Second Loop

<#foreach item1 in peopleMap["man"]> 
            ${item1.address!"Unknown"}    
</#foreach>

Is there a way to make it work? What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:25:06+00:00Added an answer on May 25, 2026 at 4:25 pm

    Not sure to be honest. This simple example works. Maybe try and strip your template down and see what happens. I thought getpeopleMapByGender() might be a typo with lowercase p, but that would mean neither loop would work.

    example.ftl

    <#assign peopleMap = context.getPeopleMapByGender()>
    
    <#foreach item in peopleMap["man"] > 
                ${item.first_name!"Unknown"} ${item.last_name!"Unknown"} 
    </#foreach>
    
    <#foreach item1 in peopleMap["man"]> 
                ${item1.address!"Unknown"}    
    </#foreach>
    

    Test class

    package grimbo.test.freemarker;
    
    import java.io.File;
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Map;
    
    import freemarker.template.Configuration;
    import freemarker.template.DefaultObjectWrapper;
    import freemarker.template.Template;
    
    public class DoubleLoop {
        public static void main(String[] args) throws Exception {
            Configuration cfg = new Configuration();
            cfg.setDirectoryForTemplateLoading(new File("./src/test/freemarker"));
            cfg.setObjectWrapper(new DefaultObjectWrapper());
            Template temp = cfg.getTemplate("example.ftl");
            Map root = new HashMap();
            root.put("context", new Context());
            Writer out = new OutputStreamWriter(System.out);
            temp.process(root, out);
            out.flush();
        }
    
        public static class Context {
            public Map getPeopleMapByGender() {
                Map m = new HashMap();
                m.put("man", Arrays.asList(new Man[] { new Man(), new Man(), new Man() }));
                return m;
            }
        }
    
        public static class Man {
            private String first_name = "first";
    
            public String getFirst_name() {
                return first_name;
            }
    
            public void setFirst_name(String first_name) {
                this.first_name = first_name;
            }
        }
    }
    

    Output

            first Unknown 
            first Unknown 
            first Unknown 
    
            Unknown    
            Unknown    
            Unknown    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm improving PHP mailing list code that uses mail() in a loop while iterating
Is iterating through the vector using an iterator and copying to a list the
Im iterating a list and getting hold of 2 fields Name and Url i
I am iterating over a list and I want to print out the index
I want to avoid the use of for loop for iterating through the HaspMap
Direct Question: I've got a simple loop with, what can be, a computationally intensive
Java Programming Issues With Iterating My Map Iterator<Player> iterator = plugin.inreview.keySet().iterator(); while (iterator.hasNext()) {
I thought I would rewrite this question (same iteration). The original was how to
When iterating over elements of a vector it is preferred to use iterators instead
When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.