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 8193331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:26:42+00:00 2026-06-07T04:26:42+00:00

I am following tutorial mentioned – http://code.google.com/p/snakeyaml/wiki/Documentation#Tutorial My code looks like public class Utilities

  • 0

I am following tutorial mentioned – http://code.google.com/p/snakeyaml/wiki/Documentation#Tutorial

My code looks like

public class Utilities {
    private static final String YAML_PATH = "/problems/src/main/resources/input.yaml";

    public static Map<String, Object> getMapFromYaml() {
        Yaml yaml = new Yaml();
        Map<String, Object> map = (Map<String, Object>) yaml.load(YAML_PATH);
        System.out.println(map);
        return map;
    }

    public static void main(String args[]) {
        getMapFromYaml();
    }
}  

my YAML file looks like

sorting
  01: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]  

When I run my program I see

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
    at com.ds.utilities.Utilities.getMapFromYaml(Utilities.java:19)
    at com.ds.utilities.Utilities.main(Utilities.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1

How can I fix this to make it work?

  • 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-06-07T04:26:44+00:00Added an answer on June 7, 2026 at 4:26 am

    It works well

    public class RuntimeInput {
        private final Map<String, Object> RUNTIME_INPUT;
    
        private static final String SORTING = "sorting";
        private static final String YAML_PATH = "/src/main/resources/input.yaml";
    
    
        public RuntimeInput() {
            RUNTIME_INPUT = getMapFromYaml();
        }
    
        public static Map<String, Object> getMapFromYaml() {
            Yaml yaml = new Yaml();
            Reader reader = null;
            Map<String, Object> map = null;
            try {
                reader = new FileReader(YAML_PATH);
                map = (Map<String, Object>) yaml.load(reader);
            } catch (final FileNotFoundException fnfe) {
                System.err.println("We had a problem reading the YAML from the file because we couldn't find the file." + fnfe);
            } finally {
                if (null != reader) {
                    try {
                        reader.close();
                    } catch (final IOException ioe) {
                        System.err.println("We got the following exception trying to clean up the reader: " + ioe);
                    }
                }
            }
            return map;
        }
    
        public Map<String, Object> getSortingDataInput() {
            return (Map<String, Object>) RUNTIME_INPUT.get(SORTING);
        }
    
        public static void main(String args[]) {
            RuntimeInput runtimeInput = new RuntimeInput();
            System.out.println(Arrays.asList(runtimeInput.getSortingDataInput()));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently followed this tutorial on Google Cloud SQL and GWT: http://code.google.com/apis/sql/docs/developers_guide_java.html I deployed
I am following the following tutorial ( http://www.highoncoding.com/Articles/642_Creating_a_Stock_Widget_in_ASP_NET_MVC_Application.aspx ) on using ajax to render
I am doing the following tutorial http://msdn.microsoft.com/en-us/library/ms731835%28v=vs.100%29.aspx and the program is working perfectly fine.
I'm using the following tutorial http://developer.android.com/resources/tutorials/views/hello-mapview.html in order to create a map view and
I have created a listview using following tutorial link http://www.ezzylearning.com/tutorial.aspx?tid=1763429 Outcome of this is,
I am following a tutorial mention on code.google , but my example fails giving
At the end of the artile here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/ It mentions the following sentence: Finally,
At the end of the article here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/ , it mentions the following: Finally,
my setup is ubuntu - gitolite - msysgit. After following this tutorial : https://sites.google.com/site/senawario/home/gitolite-tutorial
I'm running the following tutorial: http://download.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/BasicClientServer.html I'm getting the following prompts: Connected to server

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.