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 8647493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:05:12+00:00 2026-06-12T13:05:12+00:00

Error:Exception in thread main java.lang.NullPointerException at com.vipgamming.Frytree.Game.main(Game.java:47) I am not a very good programmer.

  • 0

Error:”Exception in thread “main” java.lang.NullPointerException
at com.vipgamming.Frytree.Game.main(Game.java:47)”

I am not a very good programmer. Just saying and bad Inglish.

Game.java:

package com.vipgamming.Frytree;

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {

private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width /16 * 9;
public static int scale = 3;

private Thread thread;
private JFrame frame;
private boolean running = false;

public Game() {
    Dimension size = new Dimension(width * scale, height * scale);
    setPreferredSize(size);
}

public synchronized void start() {
    running = true;
    thread = new Thread(this, "Display");
    thread.start();
}

public synchronized void stop() {
    running = false;
    try {
        thread.join();
    }catch (InterruptedException e) {
        e.printStackTrace();
    }
}

public void run() {
    while (running) {
            System.out.println("FryTree...Loading...");
        }
    }

    public static void main(String [] args) {
        Game game = new Game();
        game.frame.setResizable(true);
        game.frame.setTitle("Frytree");
        game.frame.add(game);
        game.frame.pack();
        game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        game.frame.setLocationRelativeTo(null);
        game.frame.setVisible(true);

        game.start();
    }
}

Sorry I didnt understand how to post code.(not Inglish.Portuguese)

  • 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-12T13:05:14+00:00Added an answer on June 12, 2026 at 1:05 pm

    You need to instantiate frame before using it:

    game.frame = new JFrame();
    game.frame.setResizable(true);
    ...
    

    You could also put this in the constructor:

    public Game() {
     this.frame = new JFrame();
     Dimension size = new Dimension(width * scale, height * scale);
     setPreferredSize(size);
    }
    

    If the settings defined in main are going to be the same every time then you could break that whole piece out into the constructor instead of just creating a blank one. If not, you could always overload the constructor like this:

    public Game() {//base constructor
     this.frame = new JFrame();
     Dimension size = new Dimension(width * scale, height * scale);
     setPreferredSize(size);
    }
    
    public Game(JFrame jframe)//injected frame constructor
    {
     this.frame = jframe;
     Dimension size = new Dimension(width * scale, height * scale);
     setPreferredSize(size);
    }
    

    or have Game create the settings

    public Game()
    {
     this.ConstructFrame();
     Dimension size = new Dimension(width * scale, height * scale);
     setPreferredSize(size);
    }
    
    private void ConstructFrame()
    {
        this.frame = new JFrame();
        this.frame.setResizable(true);
        this.frame.setTitle("Frytree");
        this.frame.add(game);
        this.frame.pack();
        this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.frame.setLocationRelativeTo(null);
        this.frame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the error: Exception in thread main java.lang.NullPointerException at com.deanchester.minos.utils.DatabaseManager.createTables(DatabaseManager.java:59) at com.deanchester.minos.tests.testAddContestantMethod.main(testAddContestantMethod.java:21) I
Exception in thread main java.lang.NullPointerException at com.hibernate.UserDAO.findAll(UserDAO.java:154) at test.main(test.java:12) I am getting this error
I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
Exception in thread main java.lang.NullPointerException at Library.loadBooks(Library.java:179) at UseLibrary.main(UseLibrary.java:105) This error makes me crazy!
if I run java -classpath ./sqljdbc4.jar myclassname error is Exception in thread main java.lang.NoClassDefFoundError:myclassname
I have the following error Exception in thread main javax.naming.NameNotFoundException: CounterBean not bound trying
I get the following error when I run a java program: Exception in thread
06-29 01:24:15.882: ERROR/AndroidRuntime(747): Uncaught handler: thread main exiting due to uncaught exception 06-29 01:24:15.922:
My Logcat 08-06 01:27:34.874: ERROR/AndroidRuntime(721): Uncaught handler: thread main exiting due to uncaught exception
For the following code: Model m2=ModelFactory.createDefaultModel(); m2.read(Untitled.xml); I get the error: Exception in thread

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.