Hopefully (Ha!) a nice and easy problem basically im trying to develop a simple application. The problem im getting is the "Cannot access non static method from a static context"
Unfortunately afaik the main method (ie public static void main(String[] arguments)) HAS to be static! this calls a method within the same class which then calls another method in a different class. The final method called CANNOT be static any suggestions?
Main Class Code:
public class Main {
public static void main(String[] arguments) {
int Option;
Option = Integer.parseInt( arguments[0] );
if (Option == 1) {
Main.newcity();
}
}
public static void newcity() {
String Name = "Lincoln";
String Lat = "10";
String Long = "11";
new City(Name, Lat, Long);
City.displaycity();
}
}
City Class Code
public class City {
private String Name;
private String Latitude;
private String Longitude;
/**
* Constructor for the City.
*/
public City(String cityName, String cityLat, String cityLong) {
Name = cityName;
Latitude = cityLat;
Longitude = cityLong;
}
/**
* Display the current City.
*/
public void displaycity() {
System.out.println("Name: " + Name);
System.out.println("Latitude: " + Latitude);
System.out.println("Longitude: " + Longitude);
}
}