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

  • Home
  • SEARCH
  • 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 6249619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:16:22+00:00 2026-05-24T13:16:22+00:00

I wrote a Minesweeper game that worked fine last week, but now when I

  • 0

I wrote a Minesweeper game that worked fine last week, but now when I try to run it, I get a NullPointerException, and I didn’t change the code.

There is one thing that probably is the cause: I installed Ubuntu on my laptop 2 days ago and I tried to copy my user folder from Windows to my Ubuntu desktop. I stupidly used the “move here” option because I thought that would copy the folder (there wasn’t any copy option). But when I logged back into Windows, it was as if I were a new user. So I copied that folder from my Ubuntu desktop back to Windows and fortunately all my files were back.

Here is my code. It does say MinesweeperBoard.show() is deprecated (that class extends JFrame), but the NullPointerException occurs at board = new MinesweeperBoard(9, 9, 10); even though I declared board before.

public static void main(String[] args)
{
    Scanner in = new Scanner(System.in);
    System.out.println("Do you want to play beginner (b), intermediate (i), or EXPERT (e)?");
    String input = in.next();
    MinesweeperBoard board;

    if (input.equals("b"))
        board = new MinesweeperBoard(9, 9, 10);
    else if (input.equals("i"))
        board = new MinesweeperBoard(16, 16, 40);
    else if (input.equals("e"))
        board = new MinesweeperBoard(30, 16, 99);
    else
        board = new MinesweeperBoard(30, 30, 100);

    board.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    board.show();
}

Further down in the stack trace, it points to this line of code in another class:
icons[0] = new ImageIcon(this.getClass().getClassLoader().getResource("0.gif"));

The stack trace line after that is at javax.swing.ImageIcon.<init>(Unknown Source)

I tried build all and clean, but doing those didn’t fix anything.

Edited
Entire stack trace:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at MBox.<init>(MBox.java:25)
at MinesweeperBoard.<init>(MinesweeperBoard.java:50)
at MinesweeperGame.main(MinesweeperGame.java:16)

This is from MinesweeperBoard:

for (int i = 0; i < numRows; i++)
    {
        for (int j = 0; j < numCols; j++)
        {
            boxes[i][j] = new MBox(i, j); //Line 50
            boxes[i][j].setBounds(i * SIZE + 5, j * SIZE + 65, SIZE, SIZE);
            boxes[i][j].putSelfInBoard(this);
            cont.add(boxes[i][j]);
        }
    }

This is from MBox:

    icons = new ImageIcon[12];
    icons[0] = new ImageIcon(this.getClass().getClassLoader().getResource("0.gif")); //Line 25
    icons[1] = new ImageIcon(this.getClass().getClassLoader().getResource("1.gif"));
    icons[2] = new ImageIcon(this.getClass().getClassLoader().getResource("2.gif"));
    ...
  • 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-05-24T13:16:24+00:00Added an answer on May 24, 2026 at 1:16 pm

    It sounds like the file “0.gif” isn’t in your jar file (or wherever), so getClass().getClassLoader().getResource("0.gif") is returning null. That’s then being passed to the ImageIcon constructor, which is throwing an exception.

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

Sidebar

Related Questions

I wrote a routine to remove pounds and ids from sharepoint fields that worked
I wrote a custom security provider for AES/CBC/PKCS5Padding. That works fine. What settings do
I wrote a program that forks some processes with fork(). I want to kill
I wrote a C program in Linux that mallocs memory, ran it in a
I wrote code in C# for ASP.Net website , but when i select one
Whenever I try to write graphical programs (whether a game or really any GUI
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
I wrote a component that displays a filename, a thumbnail and has a button
I wrote a simple tool to generate a DBUnit XML dataset using queries that

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.