Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8135667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:29:26+00:00 2026-06-06T10:29:26+00:00

Started making a game. Here’s some of my code. package games.tribe.screens; import games.tribe.model.World; import

  • 0

Started making a game.
Here’s some of my code.

package games.tribe.screens;

import games.tribe.model.World;
import games.tribe.view.WorldRenderer;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;

public class GameScreen implements Screen {

private World world;
private WorldRenderer renderer;

/** This was the bit I'd missed --------------------------------------**/
@Override
public void show() {
    world = new World();
    renderer = new WorldRenderer(world);
}
/**------------------------------------------------------------------**/

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    renderer.render();
}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub


}

@Override
public void hide() {
    // TODO Auto-generated method stub

}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {
    // TODO Auto-generated method stub

}

}

here’s the WorldRenderer Class:

package games.tribe.view;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;

import games.tribe.model.Block;
import games.tribe.model.TribalHunter;
import games.tribe.model.World;

public class WorldRenderer {

private World world;
private OrthographicCamera cam;

/**for debug rendering**/
ShapeRenderer debugRenderer = new ShapeRenderer();

public WorldRenderer(World world) {
    this.world = world;
    this.cam = new OrthographicCamera(10, 7);
    this.cam.position.set(5, 3.5f, 0);
    this.cam.update();
}

public void render()  {
    //render blocks
    debugRenderer.setProjectionMatrix(cam.combined);
    debugRenderer.begin(ShapeType.Rectangle);
    for(Block block : world.getBlocks()) {
        Rectangle rect = block.getBounds();
        float x1 = block.getPosition().x + rect.x;
        float y1 = block.getPosition().y + rect.y;
        debugRenderer.setColor(new Color(1, 0, 0, 1));
        debugRenderer.rect(x1, y1, rect.width, rect.height);
    }
    //render hunter
    TribalHunter hunter = world.getHunter();
    Rectangle rect = hunter.getBounds();
    float x1 = hunter.getPosition().x + rect.x;
    float y1 = hunter.getPosition().y + rect.y;
    debugRenderer.setColor(new Color(0, 1, 0, 1));
    debugRenderer.rect(x1, y1, rect.width, rect.height);
    debugRenderer.end();

}
}

This is the exception I’m getting when I run it as a desktop application:

Exception in thread "LWJGL Application" java.lang.NullPointerException
at games.tribe.screens.GameScreen.render(GameScreen.java:19)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:202)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
AL lib: ReleaseALC: 1 device not closed

Line 46 of gdx.Game.render is this method:

@Override
public void render () {
    if (screen != null) screen.render(Gdx.graphics.getDeltaTime());
}

Any help will be appreciated

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:29:27+00:00Added an answer on June 6, 2026 at 10:29 am

    In the GameScreen‘s render() method, has the renderer been initialized? That could be causing the problem if it hasn’t.

    Edit: The problem you’re having, according to the top two lines of the error, is a NullPointerException on line 19 of the class GameScreen. The NullPointerException only occurs when an object is used for some action when the object itself is null because it likely hasn’t been initialized.

    Line 19 of the GameScreen is:

    renderer.render();
    

    …but the object renderer has not been initialized anywhere, so it is currently null which is the default. To avoid getting this error, you’ll need to initialize the renderer object before you run that line of code. Perhaps with something like this:

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    
        renderer = new WorldRenderer();
        renderer.render();
    }
    

    I am not familiar with libgdx, so I can’t be sure that’s exactly how a WorldRenderer is initialized, but you need to do something of the sort. I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am current making some small JS game in Netbeans and I have started
I started making a 3d game. then I stopped for a some time and
Hi. I've got a small game using directX10 and C++. However, I started making
I have checked out code from a svn repository and started making changes. But
I recently started making a month view similar to Android 4.0's Calendar View. I
I'm just getting started on making a board game using Cocoa/Objective-C. My plan is
I'm in the process of making a game (a shmup) and I've started to
Recently, I started to make a word game which involves making words out of
I started making a game, I have a global class that reads in a
I've started making a Minesweeper game in vb.net using a dynamically created grid of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.