class useTent
{
Scanner keyboard=new Scanner (System.in);
public void main (String[] args)
{
Tent t= new Tent();
HireContract hc = new HireContract();
ProcessHire(t, hc);
}
}
this is my code, and i keep getting the same error:
" Main method is not static in class useTent, please define the main method as: public static void main(String[] args) "
and when i make the it static i get the following error:
"C:\Users\Emma\Documents\opps ass1\useTent.java:22: error: non-static method ProcessHire(Tent,HireContract) cannot be referenced from a static context ProcessHire(t, hc);"
and also still the
"Error: Main method is not static in class useTent, please define the main method as: public static void main(String[] args)"
If ProcessHire method is static and in ABC class Try this,
also follow Java Naming conventions.
The signature of
main
requiresstatic
just like the error is telling youAnd you didn't post
ProcessHire
but I think you wanted anew
and perhaps to save the referenceThe main class should be
public static void main (String[] args)
Java by default looks for a method
or say
args could be any name like public static void main (String ...arguments) {}
If you already have a public static void main method then you can have another main method which would act as normal method.
Now when you make the method static you get the other error because in a static context, calling a non static method(local to class) without initializing it's object would give error as java don't allow non static calls from static context/methods.
One example solution is make ProcessHire method static:-
or if you can't make the method static then use approach below:-