A small question of "accessed in a static way."
There is a exist example on the forum of sun:
Hi, I am working on a little java class that accesses another class to display the day of the week.
The code looks like this
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class DateTime
{
public static void main(String [] args){
WeekDay WD = new WeekDay();
Calendar currentDate =new GregorianCalendar();
int currentWeekDay = currentDate.get(Calendar.DAY_OF_WEEK );
String name =null ;
Scanner keyboardInput =new Scanner(System.in );
System.out .println("What is your name?");
name =keyboardInput.nextLine();
System.out .println("Hello, "+name+" it is "+ WD.getWeekDay(currentWeekDay) +".");
}
}
The program runs but in eclipse it shows a little yellow line under WD.getWeekDay(currentWeekDay) with a warning that says "the static method getWeekDay(int) from the type WeekDay should be accessed in a static way." Does anyone know what my prob is?
And the answer is like this:
try
System.out.println("Hello, "+name+" it is "+ WeekDay.getWeekDay(currentWeekDay) +".");
Also, if you follow any of the java coding standards, please start variables with a lower case: The variable WD should be wd
You need to configure the Eclipse compiler in the Preferences->Java->Compiler and disable some error and warning options (e.g., non-static access to static members)
The address of the content is :http://forum.java.sun.com/thread.jspa?threadID=774561&tstart=60
It gave two plans to solve the problem.I would choose the first answer if choose the most suitable answer.For the second answer may modify the standard to modify the eclipse setting.It's not promoted.
Then have a look at the question i meet:
It is a static method in the main class.I put it into a new class ,and import it in the main class.But then it appear the warn information of "the static method xxx from xxx should be accessed in a static way." I fix it as above, and know about it should not use a static method like this.And find a new problem of warn information because the new class' name should not equal the new class' method's name.