NullPointerException render Sprite



  • I know what a mistake is, but I can't figure out why it's like, in class public class ResourseLoader

    atlas = new TextureAtlas(Gdx.files.internal("texture/texture.pack"), true);
    background = new Sprite(atlas.findRegion("background"));
    

    textures packed, all in the folder введите сюда описание изображения

    in screen class

      game.batch.draw(ResourseLoader.background,0,0,1920, 1080);
    

    And there's a mistake.

    Exception in thread "LWJGL Application" java.lang.NullPointerException
    at com.badlogic.gdx.graphics.g2d.SpriteBatch.draw(SpriteBatch.java:598)
    at upwardteam.pavel.game.MainMenuScreen.render(MainMenuScreen.java:155)
    


  • Instead of background = new Sprite(atlas.findRegion("background) try to insert a background = new Sprite("some other texture" if it comes down, it means the problem in your atlas.

    If the mistake doesn't disappear, you'll start checking your SpriteBatch, Scene and other elements that you use in your project. Maybe someplace they just declared a variable, but the designer didn't add, and hence the reference to null Object.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2