Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 26, 2018 12:14 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Oct 26, 2017 10:36 pm 
Offline

Joined: Thu Oct 26, 2017 10:23 pm
Posts: 2
Hello,

I am currently using slick2D to make a small project.

The map loads and displays correctly while using eclipse, but won't load when running a jar file built with ant.

build.xml: (useful parts)
Code:
<target name="compile">
      <mkdir dir="${bin.dir}"/>
      <javac srcdir="${src.dir}" destdir="${bin.dir}">
         <classpath>
            <fileset dir="${lib.dir}">
               <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${resources.dir}">
            </fileset>
         </classpath>
      </javac>
   </target>
   <target name="jar" depends="compile">
      <mkdir dir="${jar.dir}"/>
      <mkdir dir=""/>
      <jar destfile="${jar.dir}/${jar.name}" basedir="${bin.dir}">
         <zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
         <fileset dir="${resources.dir}" />
         <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
         </manifest>
      </jar>
   </target>


How I load the map:
Code:
//inside one of my classes
URL res = getClass().getResource("/maps/main.tmx");

map = new TiledMap(res.getFile());



The error: (useful parts)
Code:
[java] java.lang.RuntimeException: Resource not found: file:/C:/Users/perso/workspace/ACL2017_Tartiflotte/exe/Tartiflotte.jar!/maps/main.tmx
     [java]     at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
     [java]     at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
     [java]     at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
     [java]     at model.Level.loadMap(Unknown Source)
     [java]     at model.Level.<init>(Unknown Source)
     [java]     at model.World.<init>(Unknown Source)
     [java]     at model.Game.<init>(Unknown Source)
     [java]     at model.GameUI.init(Unknown Source)
     [java]     at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
     [java]     at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
     [java]     at model.Main.main(Unknown Source)



I bet the error is easy to handle, something to add to build.xml, but I failed to figure what.

Could you give me a hand with this issue ?
Thanks by advance!


Last edited by viicky on Mon Oct 30, 2017 5:59 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sun Oct 29, 2017 5:08 pm 
Offline
Regular

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 160
Hello Viicky,

this is the problem line:
Quote:
URL res = getClass().getResource("/maps/main.tmx");


Could you try to load the TileMap directly? Like

Code:
TiledMap map = new TiledMap("path to tiledmap")


It will use the ResourceLoader internally
You can look at the source to see what it does


Top
 Profile  
 
PostPosted: Mon Oct 30, 2017 5:58 pm 
Offline

Joined: Thu Oct 26, 2017 10:23 pm
Posts: 2
Indeed!

In fact, seeing that my post wastn't there after 2 days, I thought that I forgot to hit the "post" button.
So I tried another forum. And they successfully helpt me.

Sorry for the inconvenience!

How do I specify that this problem is fixed?


Top
 Profile  
 
PostPosted: Tue Oct 31, 2017 8:15 pm 
Offline
Regular

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 160
Glad to hear that your issue is solved.

You didn't forget to push the post button. It can take 2 days or longer before your post is approved. We had a problem with spammers and since then each post must be manually approved by a moderator that's why..

There is no way to set the issue as resolved :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group