No such method error "main"

This code compiles, but won't run, reports no such main method

Page 1 of 1

5 Replies - 29307 Views - Last Post: 21 October 2006 - 09:37 PM Rate Topic: -----

#1 StanHelton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 21-October 06

No such method error "main"

Posted 21 October 2006 - 10:00 AM

I've been struggling with this for a week and it still eludes me. Why does "javac Pay.java" compile without errors, but "java Pay" gives the "no such method: main" error? I've tried making everything private, public, static, and void. I've gone over and over this code for typos time and again. I've even tried moving the variable declarations around from "main" to global and back again. I'm running W2k pro and jGrasp at home, but I get the same result at school running in an XP CmdPrompt in a pure Java 2 compiler/interpreter.

// THE PROGRAM
// Ex 2
// Programmer: Stan Helton -- 10/18/2006
/*	
This program demonstrates overlaoding a method to compute NetPay with 1, 2, or 3 parameters.
*/

public class Pay
{
   double grossPay, netPay, hours = 37.0, payRate = 12.16,
   withHolding= 0.16;

   public void main(String [] args)
	  {
		 computeNetPay(hours, payRate, withHolding);
		 computeNetPay(hours, payRate);
		 computeNetPay(hours);
	  }	
		
   public void computeNetPay(double hrs, double rate, double whold)
	  {
		 double gross, net;
		 gross = hrs * rate;
		 net = gross - (gross * whold);
		 System.out.println("With 3 args Net Pay is $" + net);
	  }
		
   public void computeNetPay(double hrs, double rate)
	  {
		 double gross, net, whold = 0.15;
				
		 gross = hrs * rate;
		 net = gross - (gross * whold);
		 System.out.println("With 2 args Net Pay is $" + net);
	  }
			
   public void computeNetPay(double hrs)
	  {
		 double gross, net, whold = 0.15, rate = 5.65;
				
		 gross = hrs * rate;
		 net = gross - (gross * whold);
		 System.out.println("With 1 arg Net Pay is $" + net);
	  }
}



It's probably something very simple, but I'm still learning and I don't have a feel for Java yet.

thanks,
Stan

Is This A Good Question/Topic? 0
  • +

Replies To: No such method error "main"

#2 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: No such method error "main"

Posted 21 October 2006 - 10:20 AM

Your main function must be static, like so:

public static void main(String [] args)



Hope this helps, and welcome to DIC!
Was This Post Helpful? 0
  • +
  • -

#3 StanHelton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 21-October 06

Re: No such method error "main"

Posted 21 October 2006 - 11:02 AM

I KNEW it would be something simple that I was not seeing. Thank you very much!
The code runs without problems now.

Problem solved, and lesson learned.
Thank you.

This post has been edited by StanHelton: 21 October 2006 - 11:06 AM

Was This Post Helpful? 0
  • +
  • -

#4 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1876
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: No such method error "main"

Posted 21 October 2006 - 11:37 AM

Glad jayman was able to help you out. Let us know if you have any other questions in the future, we're here to help!
Was This Post Helpful? 0
  • +
  • -

#5 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: No such method error "main"

Posted 21 October 2006 - 11:46 AM

Jayman! last I checked I was Videege
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: No such method error "main"

Posted 21 October 2006 - 09:37 PM

ROFL.

I don't mind getting the credit for your hard work. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1