Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalArgumentException: URI is not hierarchical at java.io.File.<init>(File.java:418) #12

Closed
sivareddyuppathi opened this issue Feb 15, 2020 · 12 comments

Comments

@sivareddyuppathi
Copy link

sivareddyuppathi commented Feb 15, 2020

Hi.....

I got the same error even i added new File("") in DSMBuilder

this is my sample code

DSMBuilder builder = new DSMBuilder(new File("dsm-config-file.yaml"));
DSM dsm = builder.setType(DSMBuilder.XML).create();
Pet pet = dsm.toObject(new File("path/to/xmlFile.xml"),Pet.class);

i try to solve my problem by using below question.....

java.lang.IllegalArgumentException: URI is not hierarchical..

but i codn't figure out the problem please help me..

if you want i will share my code ...

@mfatihercik
Copy link
Owner

İf you write absolute path to "dsm-config-file.yaml" it will work. Problem is not related to DSM. Java can't find the file. if the file is in your class path you should use getResourceasStrram function.

Please check #11 issue. You can find example usage getResourceasStrram. İf problem isn't solved please let me know.

@sivareddyuppathi
Copy link
Author

sivareddyuppathi commented Feb 17, 2020

Thanks for quick response .....

i wrote absolute path to builder. builder object is created

when i am trying to create dsm object i am getting the error

here is my code..

DSMBuilder builder = new DSMBuilder(new File("C:\\Users\\SivireddyUppathi\\Downloads\\split_1580192862146\\dsmYML.yml"));
DSM dsm = builder.setType(DSMBuilder.TYPE.XML).create();
Pet pet = (Pet) dsm.toObject(new File("C:\\Users\\SivireddyUppathi\\Downloads\\split_1580192862146\\dsmXML.xml"));

error in second line...

@mfatihercik
Copy link
Owner

can you please write the error you get.

@sivareddyuppathi
Copy link
Author

run:
Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.(File.java:418)
at com.github.mfatihercik.dsb.resource.FileSystemResourceAccessor.addRootPath(FileSystemResourceAccessor.java:54)
at com.github.mfatihercik.dsb.resource.AbstractResourceAccessor.init(AbstractResourceAccessor.java:39)
at com.github.mfatihercik.dsb.resource.FileSystemResourceAccessor.init(FileSystemResourceAccessor.java:47)
at com.github.mfatihercik.dsb.resource.FileSystemResourceAccessor.(FileSystemResourceAccessor.java:27)
at com.github.mfatihercik.dsb.configloader.AbstractConfigLoader.setResourceAccessor(AbstractConfigLoader.java:89)
at com.github.mfatihercik.dsb.configloader.AbstractConfigLoader.(AbstractConfigLoader.java:32)
at com.github.mfatihercik.dsb.configloader.YamlConfigLoaderStrategy.(YamlConfigLoaderStrategy.java:11)
at com.github.mfatihercik.dsb.DSMBuilder.create(DSMBuilder.java:99)
at com.ads.ammdatatypes.vo.DSMStAX.main(DSMStAX.java:38)
C:\Users\SivireddyUppathi\AppData\Local\NetBeans\Cache\11.0\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\SivireddyUppathi\AppData\Local\NetBeans\Cache\11.0\executor-snippets\run.xml:94: Java returned: 1
BUILD FAILED (total time: 1 second)

@mfatihercik
Copy link
Owner

When you pass File object to DSM.toObject, DSM assume file is in classpath if you didn't specified rootPath.
I suggest you to pass InputStream to toObject method. You can create InputStream from File.

@sivareddyuppathi
Copy link
Author

sivareddyuppathi commented Feb 17, 2020

        File ymlFile = new File("C:\\Users\\SivireddyUppathi\\Downloads\\split_1580192862146\\dsmYML.yml");
        InputStream ymlStream = new FileInputStream(ymlFile);
        DSMBuilder builder = new DSMBuilder(ymlStream);
        DSM dsm = builder.setType(DSMBuilder.TYPE.XML).create();
        File xmlFile = new File("C:\\Users\\SivireddyUppathi\\Downloads\\split_1580192862146\\dsmXML.xml");
        InputStream xmlStream = new FileInputStream(xmlFile);
        Pet pet = (Pet) dsm.toObject(xmlStream);

this is also not working for me....

for me the exception raised at below line not at toObject method...

DSM dsm = builder.setType(DSMBuilder.TYPE.XML).create();

@mfatihercik
Copy link
Owner

Only change toObject method to use input Stream.
Can you share exception trace

@sivareddyuppathi
Copy link
Author

Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.(File.java:418)
at com.github.mfatihercik.dsb.resource.FileSystemResourceAccessor.addRootPath(FileSystemResourceAccessor.java:54)
at com.github.mfatihercik.dsb.resource.AbstractResourceAccessor.init(AbstractResourceAccessor.java:39)
at com.github.mfatihercik.dsb.resource.FileSystemResourceAccessor.init(FileSystemResourceAccessor.java:47)
at com.github.mfatihercik.dsb.resource.FileSystemResourceAccessor.(FileSystemResourceAccessor.java:27)
at com.github.mfatihercik.dsb.configloader.AbstractConfigLoader.setResourceAccessor(AbstractConfigLoader.java:89)
at com.github.mfatihercik.dsb.configloader.AbstractConfigLoader.(AbstractConfigLoader.java:32)
at com.github.mfatihercik.dsb.configloader.YamlConfigLoaderStrategy.(YamlConfigLoaderStrategy.java:11)
at com.github.mfatihercik.dsb.DSMBuilder.create(DSMBuilder.java:99)
at com.ads.ammdatatypes.vo.DSMStAX.main(DSMStAX.java:38)
C:\Users\SivireddyUppathi\AppData\Local\NetBeans\Cache\11.0\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\SivireddyUppathi\AppData\Local\NetBeans\Cache\11.0\executor-snippets\run.xml:94: Java returned: 1

@mfatihercik
Copy link
Owner

The problem is not related the code. which java version are you using?

@mfatihercik
Copy link
Owner

mfatihercik commented Feb 19, 2020

#9 close this

@sivareddyuppathi
Copy link
Author

Jdk 8

@mfatihercik
Copy link
Owner

1.0.4 released. can you try new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants