Ok so im writing a small java application using Zellers Algorithm to work out the day of the week for a given date. I have never compiled a java program before because i'm still moderately new to the language and IDE's etc. I am using netbeans.

I have tried to compile the class but it comes up with an error Message saying "Could not find the main class: zellers.algorithm.Main. Program will exit."

My code is as follows:

package zellers.algorithm;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ZellersAlgorithm implements ActionListener{

    private int d;      //day of week (dd)
    private int m;      //month (mm)
    private int y;      //year born (yyyy)
    private String[] DAY_OF_WEEK = {"Sunday","Monday", "Tuesday", "Wednesday",
    public String date;     //Date entered into text field

    //GUI objects
    JTextField dateInput;
    JButton submit;
    JLabel result;

    public ZellersAlgorithm(){
        date = "";



    public void setupInterface(){
        //Create window objects
        dateInput = new JTextField(10);

        submit = new JButton("Find Day");

        JLabel inst = new JLabel("Enter the date (dd/mm/yyyy): ");

        result = new JLabel();

        FlowLayout flo = new FlowLayout();

        //create new window
        JFrame window = new JFrame();
        window.setTitle("Zellers Algorithm");

        //Add objects to window

    public void actionPerformed(ActionEvent event){
        Object source = event.getSource();
        if(source == submit){
           date = dateInput.getText();

        public void implmentZellers(){
        //implements the zellers algorithm
             * Let day = d
             * Month = m
             * Year = y
             * if m < 3
             *      m +=12
             *      y--;
             * let A = first 2 digits of y
             * let B = last 2 digits of y
             * myResult = int(2.6M - 5.39) + int (B/4) + int (A/4) + d + b - 2A
             * find remainder of (myResult / 7)
             * dayNames[remainder]

            //Splits date string into Day month and year
            String splitItems[] = date.split("/");
            d = Integer.parseInt(splitItems[0]);
            m = Integer.parseInt(splitItems[1]);
            y = Integer.parseInt(splitItems[2]);


            if (m < 3){

                m += 12;
                System.out.println("m < 3");
                System.out.println("Month: " + m);
                System.out.println("Year: " + y);

            int A;
            int B;
            double myResult;

            A = y / 100;
            System.out.println("A: " + A);
            B = y % 100;
            System.out.println("B: " + B);

            //myResult = int(2.6m - 5.39) + int (B/4) + int (A/4) + d + B - 2A
            myResult = ((int)((2.6 * m)-5.39)) + ((int)(B/4)) + ((int)(A/4)) + d + B - (2*A);

            //remainder of myResult is index for the day born in DAY_OF_WEEK
            System.out.println("DOW: " + DAY_OF_WEEK[(int)myResult % 7]);

            result.setText("The day was a " + DAY_OF_WEEK[(int)myResult % 7]);

    public static void main(String[] args) {
         new ZellersAlgorithm();


I assumed that this would compile as is has the main method but for some reason it won't.

Can anyone help with this either by ammending the code or by instructing me how to compile the file. I can use cmd as well as Netbeans and I also have Eclipse so any suggestions welcome.

Thank you in advance

4 Years
Discussion Span
Last Post by NormR1

compile the class but it comes up with an error Message saying "Could not find the main class: zellers.algorithm.Main. Program will exit."

That sounds like an execution time error, not an error from the javac compiler program.

Do you understand packages and how putting a class in a package will change where the java command looks for the class file. It is a lot easier for a beginner to work without packages so that there is no problems with where the class files are located, where the java command is executed and what the contents of the classpath is. IDEs should take care of those details, but they may require that they are properly configured.

What happens when you use the javac command in a command prompt window?


I tried the command prompt using the javac function to create a .class file.

I then used the jar function to create a .jar file but on execution a similar error message occurs "Failed to load Main-Class manifest attribute from (path)"


The jar file must contain a valid manifest file and the class files in the jar file must be located in the correct directories. There are more details that I can list here. Do some research on how to create a valid jar file.


I've already tried looking for a solution but just cant find anything that seems to work. Can you give me some directions on how to do this.


Here is a batch file I use to create a jar file:

@Rem create the CmprFolders.jar file:
cd %DEV_HOME%\JavaDevelopment\NormsTools\CmprFolders\
jar -cmf  CmprFolders.mnf  %JAVA_RUN%\CmprFolders.jar  *.class CmprFolders.html
cd D:\JavaDevelopment\
jar -uf  %JAVA_RUN%\CmprFolders.jar  NormsTools\ChoiceOfYesOrNo*.class NormsTools\ErrDialog*.class NormsTools\GetInput*.class NormsTools\MessageArea*.class NormsTools\SaveStdOutput*.class NormsTools\ShowMsgBox*.class NormsTools\MakeEnterDoAction*.class NormsTools\BigTextArea*.class NormsTools\AskMultipleChoices*.class NormsTools\ShowCounters*.class NormsTools\FolderList*.class NormsTools\EditableList*.class NormsTools\ArrayUtil*.class
@ECHO -------- Finished creating: %JAVA_RUN%\CmprFolders.jar  ----------

And here is the manifest:

Main-Class: CmprFolders
Class-Path: DocumentViewerWParser.jar

The names in %s are for environment variables which contain paths to folders on my PC

Edited by NormR1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.