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

Null Pointer Exception #9

Closed
Route-7 opened this issue May 12, 2015 · 12 comments
Closed

Null Pointer Exception #9

Route-7 opened this issue May 12, 2015 · 12 comments

Comments

@Route-7
Copy link

Route-7 commented May 12, 2015

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 👍

@xaguzman
Copy link
Owner

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
Copy link
Author

Route-7 commented May 14, 2015

Hi, I'm using libgdx 1.5.6.

@xaguzman
Copy link
Owner

I mean version of the pathfidnig library

@Route-7
Copy link
Author

Route-7 commented May 14, 2015

0.2.5

@xaguzman
Copy link
Owner

xaguzman commented Aug 4, 2015

Hello, are you still having this issue?

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

@AmazingDreams
Copy link

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

EDIT: never mind, was in my own code.

@xaguzman
Copy link
Owner

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
Copy link

jeltedeproft commented Nov 27, 2016

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
Copy link
Owner

Could you share your tmx file along with your tilesets?

@jeltedeproft
Copy link

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
Copy link

sorry

@xaguzman
Copy link
Owner

xaguzman commented Nov 29, 2016 via email

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

No branches or pull requests

4 participants