Unable to load map with libtiled-java
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 12.9k
- Forks
- 2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 8
Description
The following code is not working for me
``` java
final TMXMapReader reader = new TMXMapReader();
final InputStream stream = this.class.getClassLoader().getResourceAsStream("maps/level_1.tmx");
final Map map;
try {
map = reader.readMap(stream);
} catch (Exception e) {
e.printStackTrace();
}
```
I am getting the following error:
```
[Fatal Error] :1:1: Content is not allowed in prolog.
org.xml.sax.SAXParseException; systemId: file:/C:/Users/Robert/IdeaProjects/platform-game/./; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
at tiled.io.TMXMapReader.unmarshal(Unknown Source)
at tiled.io.TMXMapReader.readMap(Unknown Source)
at me.robertmaes.platform_game.Game.(Game.java:70)
at me.robertmaes.platform_game.Game.main(Game.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
java.lang.Exception: Error while parsing map file: org.xml.sax.SAXParseException; systemId: file:/C:/Users/Robert/IdeaProjects/platform-game/./; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at tiled.io.TMXMapReader.unmarshal(Unknown Source)
at tiled.io.TMXMapReader.readMap(Unknown Source)
at me.robertmaes.platform_game.Game.(Game.java:70)
at me.robertmaes.platform_game.Game.main(Game.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
```
I have already verified the stream is loading correctly. What am I doing wrong here?
Also, here is the source of the file I am trying to load:
``` xml
eJzjYGBg4ABiaSSMjc+BJk4sG5teWtpBD0yqP3Cpp2ZYkWIHOx0xNvfBMLHq8OkbDJgFhxguzI7GJgQkiFBDjB4+GuJRO0btAGEpNHoo+WM4AACJ2xaV
eJzVk0sKwzAMRCdJuwg09LcogRyuR+tRawcLjLGlUU0WFbxVZjQWUhYAM8FC6mq+CFNRdye1pS8yEYgOpD73eeaYO+ZgtWNiMrS1jN6dw/B55gB8u2jt4xl4KBmi0Ur8ecYrcGqQZ2yBs9G/9raLAQiN5Rmw38rH+Ty15O5C3/dwYMbNmXF19pc6Yo7y32Qz5M6tnjXNr3NomVpGytlZ0/e1ZXRUmdFi7IDp/098AciFDG4=
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Java snippet with TMXMapReader.readMap and inspect the resource stream and TMX file shown in the report. Then trace the parser entry point named in the stack trace, tiled.io.TMXMapReader.unmarshal. Done means the reported map loads without the SAX prolog error and the cause is documented or reproducible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100