LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2018, 09:31 PM   #1
dy20082250
Member
 
Registered: Oct 2013
Location: China
Distribution: Fefora 9
Posts: 81

Rep: Reputation: Disabled
the question about parse yaml file


Code:
java.lang.VerifyError: org/ho/yaml/ReflectionUtil
at org.ho.yaml.JYamlParserEvent.<init>(Unknown Source)
at org.ho.yaml.YamlDecoder.readObjectOfType(Unknown Source)
at org.ho.yaml.YamlConfig.loadType(Unknown Source)
at org.ho.yaml.YamlConfig.loadType(Unknown Source)
at org.ho.yaml.Yaml.loadType(Unknown Source)
at com.eisoo.content.locator.ElementLocator.getLocatorMapFromYamlFile(ElementLocator.java:34)
when the program run:

Code:
locatorMap = Yaml.loadType(new FileInputStream(yamlFile.getAbsolutePath()), HashMap.class);



I am sure that the yaml file is correct and I have checked it so many times
below is the yaml file,its name is common.yaml:

#========user login============#
tap:
type:text
value:"me"

PS: I am using jyaml.jar-1.3

Last edited by dy20082250; 01-24-2018 at 09:51 PM.
 
Old 01-25-2018, 05:53 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
As no one else has stepped up I will try to offer some direction...

First, your question appears to include an error message, but does not include the section of the file which is producing the error. It would be difficult for anyone to provide help without knowing what input is producing the error.

Next, I would suggest using your search engine of choice to look for similar problems and solutions already available, which is what I have had to do. Searching for "parse yaml with java" produces many useful looking hits. Looking over those results it appears to me that different parsers produce different results from the same yml input file - which makes finding an answer somewhat hit-or-miss.

jyaml is the original java yml parser implementation, but I see many references to the Jackson-yaml-module as a better, specifically more reliable alternative.

You can find reference information for many yaml parser implementations at Yaml.org, including jyaml which you are using.

If you still cannot find help, please post the file, or section of the file which produces the error, along with a more complete description of how you invoke the program and the complete error it produces.

Good luck!

Last edited by astrogeek; 01-25-2018 at 05:57 PM. Reason: typos yml=yaml
 
Old 01-25-2018, 06:10 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I think this part was supposed to indicate the input, though it suffered from lack of [code][/code] tags:

Code:
#========user login============#
tap:
  type:text
  value:"me"
I don't really know much about yaml or jyaml, but something to try would be to cut down even further to see which part causes problems, e.g., take out the quotes around "me", does just a bare
Code:
tap:me
work?
 
1 members found this post helpful.
Old 01-26-2018, 03:11 AM   #4
dy20082250
Member
 
Registered: Oct 2013
Location: China
Distribution: Fefora 9
Posts: 81

Original Poster
Rep: Reputation: Disabled
Hi All

I have found the root cause

it is the jyaml.jar,in android platform,this jar can not be used

I have found a new jar :snakeyaml-1.18-android.jar

But I found that the code used to parse is not perfect:

Code:
private Map getLocatorMapFromYamlFile(String fileName)  {
        File yamlFile = new File("/sdcard/pagelocator/" + fileName + ".yaml");
        Map locatorMap = null;

        if(!yamlFile.exists() || !yamlFile.canRead())
            return locatorMap;
        try {
            Yaml yaml = new Yaml();
            locatorMap = (Map)yaml.load(new FileInputStream(yamlFile.getAbsolutePath()));
            System.out.println("load yaml successfully");
        } catch (Exception e) {
            LogUtil.warn("WARNING: Fail to read yaml file: " + fileName + ".yaml");
        }
        return locatorMap;
    }

public UiSelector getLocator(String key, ArrayList<String> locatorStringReplacement) {
        UiSelector locatorBy = null;
        if (_locatorMap == null)
            return null;
        String type[] = null;
        String value[] = null;
        if (_locatorMap.containsKey(key)) {
            //get the value of the keyword
            String indexValue = _locatorMap.get(key).toString();
            //slice to type and value, index 0 is type and index 1 is value
            String typeAndValue[] = indexValue.split(" ");
            //slice type
            type = typeAndValue[0].split(":");
            //slice value
            value = typeAndValue[1].split("value:");

          
            if (type[1].equals("text") && null!=value[1])
                locatorBy = new UiSelector().text(value[1]);
            else if (type[1].equals("ctext"))
                locatorBy = new UiSelector().textContains(value[1]);
            else if (type[1].equals("stext"))
                locatorBy = new UiSelector().textStartsWith(value[1]);
            else if (type[1].equals("id"))
            { System.out.println(value[1]);
                locatorBy = new UiSelector().resourceId(value[1]);}
            else if (type[1].equals("classname"))
                locatorBy = new UiSelector().className(value[1]);
            else if (type[1].equals("desc"))
                locatorBy = new UiSelector().description(value[1]);
            else if (type[1].equals("sdesc"))
                locatorBy = new UiSelector().descriptionStartsWith(value[1]);
            else if (type[1].equals("cdesc"))
                locatorBy = new UiSelector().descriptionContains(value[1]);
        else{
            LogUtil.error("The locator with specified name " + key + " does not exist.");
        }
        return locatorBy;
    }
it is useful to my issue,but I think there should be other better methods
I did not construct a good data structure to parse:

Code:
#========user login============#
tap:
  type:text
  value:"me"

Last edited by dy20082250; 01-26-2018 at 03:15 AM.
 
Old 01-26-2018, 03:19 AM   #5
dy20082250
Member
 
Registered: Oct 2013
Location: China
Distribution: Fefora 9
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
I think this part was supposed to indicate the input, though it suffered from lack of [code][/code] tags:

Code:
#========user login============#
tap:
  type:text
  value:"me"
I don't really know much about yaml or jyaml, but something to try would be to cut down even further to see which part causes problems, e.g., take out the quotes around "me", does just a bare
Code:
tap:me
work?
In fact the "me" is working for my program, of course ,take out the quotes around "me" is also working,it is not the root cause
 
Old 01-26-2018, 03:22 AM   #6
dy20082250
Member
 
Registered: Oct 2013
Location: China
Distribution: Fefora 9
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
As no one else has stepped up I will try to offer some direction...

First, your question appears to include an error message, but does not include the section of the file which is producing the error. It would be difficult for anyone to provide help without knowing what input is producing the error.

Next, I would suggest using your search engine of choice to look for similar problems and solutions already available, which is what I have had to do. Searching for "parse yaml with java" produces many useful looking hits. Looking over those results it appears to me that different parsers produce different results from the same yml input file - which makes finding an answer somewhat hit-or-miss.

jyaml is the original java yml parser implementation, but I see many references to the Jackson-yaml-module as a better, specifically more reliable alternative.

You can find reference information for many yaml parser implementations at Yaml.org, including jyaml which you are using.

If you still cannot find help, please post the file, or section of the file which produces the error, along with a more complete description of how you invoke the program and the complete error it produces.

Good luck!
I have suffered this issue for three days and search on google and tried many methods,but did not found the root cause
in the end , a developer told me that the jar can not be used on android.........
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] upgrading ruby from 1.9.1 to 1.9.3 and psych yaml error alanware Slackware 2 05-24-2012 02:33 AM
Parse a CSV file output to text file beto Linux - Newbie 3 04-25-2012 08:45 AM
Parse file from remote server to caculate count of string existence in that file saurabhmehan Linux - Newbie 2 08-30-2010 12:30 AM
reading YAML config into Perl as @list. OldGaf Programming 12 06-16-2010 07:31 AM
problems iterating in RUBY while extracting info from YAML, Pls help! wrapster Programming 0 10-04-2008 09:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration