• Post Reply Bookmark Topic Watch Topic
  • New Topic

HelP!  RSS feed

 
Gavin Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need some help with the code below. The general idea of the code is to propmt the user for different int values and output these values in a formatted way, this invloves alot of loops and for loops. All looks well apart from the message: "expection in thread "main" "....


here is the code:

import java.io.*;
import java.text.*;


public class prac10weather1
{
static BufferedReader myInput = new BufferedReader(new InputStreamReader( System.in));


// defining new arrays that will hold 7 values for 7 days of the week
static int max_temp [] = new int [7];
static int min_temp [] = new int [7];
static int humidity [] = new int [7];


static int i; // it is very important that these two variables are declared as 'static'
static int n; // doing this ensures that they are available throughout the entire program

// static program variables that are available throughout the program
static int maxTemp;
static int minTemp;
static int hum;
static int NumberOfDays;
static int NumberOfStars;
static String input_string_number_of_days;
static String input_String_max_temp;
static String input_String_min_temp;
static String input_String_hum;


public static void readInput() throws IOException
{
// Here the user is prompted for the number of days
// The number is then put into a new variable called NumerOfDays
System.out.print("How many days weather do you wish to enter?: ");
input_string_number_of_days = myInput.readLine();
int NumberoOfDays = Integer.parseInt(input_string_number_of_days);

for(int n=0; n<NumberOfDays; n++)
{
System.out.println("Enter the Max temperature for Day "+n);
input_String_max_temp = myInput.readLine ();
maxTemp = Integer.parseInt(input_String_max_temp);

System.out.println("Enter the Min temperature for Day "+n);
input_String_min_temp = myInput.readLine ();
minTemp = Integer.parseInt(input_String_min_temp);

System.out.println("Enter the Humidity for Day "+n);
input_String_hum = myInput.readLine ();
hum = Integer.parseInt(input_String_hum);

// after we read the values into the above variables we need to populate the arrays
// the 3 lines of code below populates the max, min & hum arrays with
// the appropriate variable values
humidity[n] = maxTemp;
min_temp[n] = minTemp;
max_temp[n] = hum;
}




}
public static void printResult()
{
System.out.println("-------------------");
System.out.println("Day / Maximum Temp");
System.out.println("-------------------");


for (n=0; n<NumberOfDays; n++)
{
System.out.print(n+min_temp[n]+" ");
NumberOfStars = min_temp[n]/4;

for (i=0; i<NumberOfStars; i++)
{
System.out.print("*");

}

}
}



}


Thank you!!!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

All looks well apart from the message: "expection in thread "main" "....


And what does the rest of the message say? It should be telling you what is wrong.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This ought to be in the beginner forum, not intermediate, but anyway...
Where is your main method? And watch out, you are probably confusing
variables NumberoOfDays and NumberOfDays. you should try to minimize
the number of static variables you are defining -- they are not your friends.
 
Gavin Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help:

the main message is: ...java.lang.NoSuchMethodError: main

does that help?

Many Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gavin Walsh:

does that help?


NoSuchMethodError: main =>
No Such Method Error: main =>
The error is: No Such Method: main =>
There's no method named "main"

Do you understand the message now?
 
Gavin Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah a bit more...but is 'main' a generic term? because there is nothing in my script that mentions main...
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gavin Walsh:
yeah a bit more...but is 'main' a generic term? because there is nothing in my script that mentions main...


By "script" do you mean program? Every Java program needs a main method.
Yours should be something like
If you aren't aware of main, you really need to do some tutorials:
http://java.sun.com/docs/books/tutorial/getStarted/index.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!