Hi all,

I'm new to Java.

I'm having a problem with a program which will compile but not run.
When I run it, I get the following error:

  java.lang.NoSuchMethodError: main
  Exception in thread "main" 
 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.

The name of the program is the name of the "main" class.

Any help would be greatly appreciated.

The program with the problem is as follows:

/***********************************************
* Name: 
* Purpose:
* 
*       
* Date: 07/22/2005
* Author: 
* References: None
**************************************************/    
import cs1.Keyboard;
import java.io.*;

class People 
{
    String name;
     double height;
     double weight;
     String sex;

public People()
{
   name = " ";
    height = 0.00;
    weight = 0.00;
    sex = " ";
}  

public People(String name, double height, double weight, String sex)
{
   this.name = name;
    this.height = height;
    this.weight = weight;
    this.sex = sex;
}  

public void BodyMassIndex()
{
  double bmi = 0.00;
  bmi = weight /(height * height);
  System.out.println("test: bmi"+bmi+" "+name+" "+height+" "+weight);
}
}

class PatientBMI
{
  public void main(String[] args) throws IOException
   {

  int numclasses = 0;
  boolean i = true;

  while (i)
   {

      People patient = new People();
      System.out.println("Enter the following information for the patient: ");
      System.out.print("   Full name: ");
      patient.name = Keyboard.readString();
      System.out.print("\n");
      System.out.print("   Height: ");
      patient.height = Keyboard.readDouble();
      System.out.print("\n");
      System.out.print("   Weight: ");
      patient.weight = Keyboard.readDouble();
      System.out.print("\n");
      System.out.print("   Weight: ");
      patient.sex = Keyboard.readString();
      System.out.print("\n");
      patient = new People(patient.name, patient.height, patient.weight, patient.sex);
      patient.BodyMassIndex();
     } 
  }
}

Thanks,

class PatientBMI
{
public void main(String[] args) throws IOException
{

int numclasses = 0;
boolean i = true;

while (i)
{

People patient = new People();
System.out.println("Enter the following information for the patient: ");
System.out.print(" Full name: ");
patient.name = Keyboard.readString();
System.out.print("\n");
System.out.print(" Height: ");
patient.height = Keyboard.readDouble();
System.out.print("\n");
System.out.print(" Weight: ");
patient.weight = Keyboard.readDouble();
System.out.print("\n");
System.out.print(" Weight: ");
patient.sex = Keyboard.readString();
System.out.print("\n");
patient = new People(patient.name, patient.height, patient.weight, patient.sex);
patient.BodyMassIndex();
}
}
}

Well first things first. I tend to declare my classes as public but i'm not 100% sure thats required but it is required to declare your main method as...

public static void main(String args[])

You forgot to make main static which is required since you dont actually have an instance of the main method. Thats why you get the error not sure if the rest of ur code is good or not but since you asked about the error. Thats your answer.

The missing "static" in the main was it.

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.