Search code examples
java.class-file

Bad class file when calling in another java file


When declaring a java file in another java file I get the following error.

Bad Class File

The java file which is causing the error has the following code in

public class NumberSettingsFile
{
    int maxSortBoxes = 50;

    public int getMaxSortBoxes()
    {
        return maxSortBoxes;
    }
}

And I am declaring it using the following code

NumberSettingsFile uniSet = new NumberSettingsFile();

Would someone please be able to explain what I am doing wrong?


Solution

  • The problem was caused by not declaring the package in which the java file was in. The code should have read

    package GUIMain;
    
    public class NumberSettingsFile
    {
        int maxSortBoxes = 50;
    
        public int getMaxSortBoxes()
        {
            return maxSortBoxes;
        }
    }