Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Error Message " Public Main must be defined in own file ( Java 16777541) -How Do i resolve it

  1. #1
    Junior Member
    Join Date
    Sep 2024
    Location
    Traverese City
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Error Message " Public Main must be defined in own file ( Java 16777541) -How Do i resolve it

    Using Viscode Creating simple Java program ( My robotic files import the libraries WPILIB for the my robotic codes , however, when i construct a simple tutorial file I run into that error on the first line " public Main must be Identified ..."
    How do i create the ( Main ) file and where does it get places so that the program below can execute.
    and if I'm correct
    it appears that swerveDrive must somehow be resolved to the variables and it not being declared or recognized
    I hope you understand the issue inspite on my poorly word issue

    Program below
     public class Main {
     
     
     
     
        public static void main ( String ... args) {
            Robot swerveDrive = new Robot();   // create object instance of class
     
            swerveDrive.wheeldia = 3.0;  // inches
            swerveDrive.piniongearteeth = 12.00;
            swerveDrive.spurgearteeth = 14.00;
            swerveDrive.bevelgearteeth = 12.00;
            swerveDrive.wheelgearteeth = 44.00;
     
            swerveDrive.chassisspeedforward = 1.00; // meter per sec
            swerveDrive.Neomotorkv = 473.00;    // see Neo bushless motor spec sheet 
            swerveDrive.Neomotorfreerpm = 5676.00;   // rpm see spec sheet 
            swerveDrive.Neomotornomvoltage = 12.00;  // volts see spec sheet 
     
            System.out.println(" RobotSwerevDriveMotorVoltage is: " + swerveDrive.calculateVoltage());
     
        }
     
        static class Robot{
            double wheeldia;                      //  Define variable as integer or numericalwithdecimal
            double piniongearteeth;
            double spurgearteeth;
            double bevelgearteeth;
            double wheelgearteeth;
            double chassisspeedforward;
            double Neomotorkv;
            double Neomotorfreerpm;
            double Neomotornomvoltage;
     
            // create a method to calculate motor voltage and return value to main class 
     
            double calculateVoltage(){
                double Voltage;
     
                Voltage =   ((( chassisspeedforward * 39.37)/(wheeldia * 3.1416 )) * 60.0*((spurgearteeth/piniongearteeth)*(wheelgearteeth/bevelgearteeth))/(Neomotorkv));  
                return  Voltage ;    
            }
     
        }   
    }
    Last edited by Norm; September 11th, 2024 at 10:47 PM. Reason: Added code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,098
    Thanks
    65
    Thanked 2,715 Times in 2,665 Posts

    Default Re: Java Error Message " Public Main must be defined in own file ( Java 16777541) -How Do i resolve it

    Sorry, I do not know anything about Viscode.
    Public Main must be defined in own file
    A public class must be defined in its own file and the name of the file must be <classname>.java. For example a public class named Main must be contained in a file named: Main.java

    A program that uses classes declared in a package must include import statements that refer to that package.
    Note: Robot is the name of a java class. It is better to not use names of java classes.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: November 26th, 2021, 08:48 AM
  2. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  3. Replies: 1
    Last Post: February 27th, 2013, 06:48 AM
  4. [SOLVED] Error Message: Exception in thread "main" java.lang.NullPointerException etc.
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 15th, 2011, 09:34 AM
  5. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM