0

I am working on an game assignment for my class in eclipse. I have been getting an error:

ClassNotFoundException(throwable);

It stops in

public static Jewel[][] grid = new Jewel[8][8];

While running the debugger it doesnt seem to enter the new Jewel[8][8]

i certanly have the Jewel Class in the same package, and i cant figure out why it cant find the class. I am assuming that it is trying to generate a different class or the static portion of the class is not being generated at compile time. Any additional comments are welcome;

here is the whole class this is located in

package game;

import java.awt.Dimension; 
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class PlayArea extends JPanel {

    private static final long serialVersionUID = -9165676032115582474L;

    public static Jewel[][] grid = new Jewel[8][8];

    public PlayArea(){

        this.setPreferredSize(new Dimension(Common.jewelWidth*Common.rowColLength,Common.jewelWidth*Common.rowColLength));
        this.setLayout(null);

        for(int i = 0; i < Common.rowColLength; i++){
            for (int j = 0; j < Common.rowColLength; j++){
                grid[i][j] = new Jewel();
            }
        }
    }

    @Override
    public void paintComponent(Graphics g){
        Graphics2D g2 = (Graphics2D) g;
        for (int i = 0; i <Common.rowColLength;i++){
            for(int j = 0; j < Common.rowColLength; j++){
                grid[i][j].drawJewel(i, j, g2);
            }
        }
        Jewel grid2 = new Jewel();
        grid2.drawJewel(1, 1, g2);
    }
}
Kraczekj
  • 1
  • 3
  • Post the stack trace to the exception I guess. When you say the error is `ClassNotFoundException(throwable)`, that's what it says? It doesn't name a class? When you say "it stops in" you mean the exception throws there or the debugger skips over it? (It won't enter anything there, the existing answers are right about that.) – Radiodef Feb 28 '14 at 04:48
  • while running the debugger it pauses there and throws that object/error. i wonder if i have to clean/ rebuild/ tell eclipse to re-look at the files or something because i commented out that line entirely and it gave the same error, – Kraczekj Feb 28 '14 at 05:35
  • If cleaning and rebuilding doesn't work, post the stack trace because it might tell us something useful. Cleaning and rebuilding is always a good idea in a circumstance like this. – Radiodef Feb 28 '14 at 05:42
  • I re-wrote the file to exclude the Jewel class after checking the stack trace. and that seems to have fixed my issue and everything seems to be working swimmingly. i suppose i should have designed the code better from the beginning. Thanks for suggesting to check the Stack Trace. - If you answer with something along those lines i would gladly mark that as answered. – Kraczekj Feb 28 '14 at 06:39

2 Answers2

-1
public static Jewel[][] grid = new Jewel[8][8];

This will not create instances of Jewel class but merely references to it. You have to explicitly iterate over your 2D array and create new Jewel instances.

grid[i][j] = new Jewel();

This is where it will go inside the constructor if you have some code in your default constructor.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
-1
While running the debugger it doesnt seem to enter the new Jewel[8][8].

It wont't enter jewel[8][8] because array indices start from 0. i.e; from 0-7 (count=8)

TheLostMind
  • 35,966
  • 12
  • 68
  • 104