xaguzman / pathfinding

Java pathfinding framework.
Apache License 2.0
97 stars 27 forks source link

Null Pointer Exception #9

Closed Route-7 closed 8 years ago

Route-7 commented 9 years ago

Hi, I really like your library, I've been able to load a tmx map but when I try to find a path, I get this:

Exception in thread "LWJGL Application" java.lang.NullPointerException
    at org.xguzm.pathfinding.finders.AStarFinder.findPath(AStarFinder.java:56)
    at org.xguzm.pathfinding.grid.finders.AStarGridFinder.findPath(AStarGridFinder.java:32)
    at com.route7.td.ai.Grid.getPath(Grid.java:32)
    at com.route7.td.map.Map.findPath(Map.java:187)
    at com.route7.td.sprites.Enemy.setDestination(Enemy.java:74)
    at com.route7.td.map.Level.show(Level.java:90)
    at com.badlogic.gdx.Game.setScreen(Game.java:61)
    at com.route7.td.screens.LevelSelect$2.changed(LevelSelect.java:158)
    at com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.handle(ChangeListener.java:28)
    at com.badlogic.gdx.scenes.scene2d.Actor.notify(Actor.java:181)
    at com.badlogic.gdx.scenes.scene2d.Actor.fire(Actor.java:146)
    at com.badlogic.gdx.scenes.scene2d.ui.Button.setChecked(Button.java:116)
    at com.badlogic.gdx.scenes.scene2d.ui.Button$1.clicked(Button.java:90)
    at com.badlogic.gdx.scenes.scene2d.utils.ClickListener.touchUp(ClickListener.java:89)
    at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:57)
    at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:348)
    at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:306)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:206)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

Here is my code:

import org.xguzm.pathfinding.gdxbridge.NavigationTiledMapLayer;
import org.xguzm.pathfinding.grid.GridCell;
import org.xguzm.pathfinding.grid.finders.AStarGridFinder;
import org.xguzm.pathfinding.grid.finders.GridFinderOptions;

import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.math.Rectangle;
import com.route7.td.map.Map;

public class Grid {

    public AStarGridFinder<GridCell> finder;

    public NavigationTiledMapLayer pathLayer;
    public TiledMap map;

    public Grid(Map tmxMap) {
        TiledMap map = new NavTmxMapLoader().load(tmxMap.tmxFile);
        pathLayer = (NavigationTiledMapLayer) map.getLayers().get("navigation");

        GridFinderOptions opt = new GridFinderOptions();
        opt.allowDiagonal = false;

        finder = new AStarGridFinder<GridCell>(GridCell.class, opt);
    }

    public List<GridCell> getPath(Rectangle start, Rectangle end) {
        return finder.findPath((int)start.x, (int)start.y, (int)end.x, (int)end.y, pathLayer);
    }
}

Any help would greatly be appreciated :+1:

xaguzman commented 9 years ago

Hello, sorry for the late reply.

Im very very short on time lately for personal projects (such as this). I'm afraid I don't really know when I will be able to check it up, probably not before august.

What version are you using? Last time a bug like this was reported was because the row | column of each GridCell were not being automatically-assigned when creating the Grid. Not sure this could be your problem since you are using the gdx-bridge it seems...

Route-7 commented 9 years ago

Hi, I'm using libgdx 1.5.6.

xaguzman commented 9 years ago

I mean version of the pathfidnig library

Route-7 commented 9 years ago

0.2.5

xaguzman commented 8 years ago

Hello, are you still having this issue?

In case you are, is it possible for you to provide your tmx file?

AmazingDreams commented 8 years ago

I also have this issue. It seems to occur when no path can be found.

EDIT: never mind, was in my own code.

xaguzman commented 8 years ago

Glad you found solved your problem.

Since OP hasn't said anything about this...im just gonna close this and reopen it if needed...

jeltedeproft commented 7 years ago

hey i have the same problem :(

public AStarGridFinder<GridCell> finder;

tiledMap = new NavTmxMapLoader().load("orthogonale map/6v6.tmx");

NavigationTiledMapLayer navLayer = (NavigationTiledMapLayer) tiledMap.getLayers().get("navigation");
finder = new AStarGridFinder<GridCell>(GridCell.class);

System.out.println(finder.findPath( 0, 0, 5, 5, navLayer));

gives me the error : Exception in thread "LWJGL Application" java.lang.NullPointerException

xaguzman commented 7 years ago

Could you share your tmx file along with your tilesets?

jeltedeproft commented 7 years ago

oopsy daisy, fixed it, my problem was that i had copy pasted my old map and i was working with a copy in stead of original, your library works like a charm

jeltedeproft commented 7 years ago

sorry

xaguzman commented 7 years ago

I'm glad it's being useful for your project :)


Xavier Guzman

http://blog.xavierguzman.com http:////plus.google.com/u/0/113140404022814604923? http://mx.linkedin.com/in/xavierguz/ https://twitter.com/arkalain

Blog http://blog.xavierguzman.com | G+ http:////plus.google.com/u/0/113140404022814604923? | LinkedIn http://mx.linkedin.com/in/xavierguz/ | Twitter https://twitter.com/arkalain

On Tue, Nov 29, 2016 at 1:39 PM, jeltedeproft notifications@github.com wrote:

sorry

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/xaguzman/pathfinding/issues/9#issuecomment-263675670, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZ27t479LYHxj93pzelY-ZMHf1kx9kks5rDH9ogaJpZM4EXSim .