RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1368 | Replies: 2
Reply
Join Date: Apr 2005
Posts: 27
Reputation: bobr_1013 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bobr_1013 bobr_1013 is offline Offline
Light Poster

Help - Run time error

  #1  
Jul 23rd, 2005
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,
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Posts: 56
Reputation: Sauce is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Sauce Sauce is offline Offline
Junior Poster in Training

Re: Help - Run time error

  #2  
Jul 23rd, 2005
Originally Posted by bobr_1013
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.
Reply With Quote  
Join Date: Apr 2005
Posts: 27
Reputation: bobr_1013 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bobr_1013 bobr_1013 is offline Offline
Light Poster

Re: Help - Run time error

  #3  
Jul 23rd, 2005
The missing "static" in the main was it.

Thanks,
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:28 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC