ERROR: non-static variable this cannot be referenced from static context

import java.util.*;

import java.io.*;

public class FinalCalculator{

static Scanner console = new Scanner(System.in);

public static void main(String[] args){

int days = 21;

int month = 3;

int year = 2002;

char era = 'a';

String name;

System.out.println("Please enter the name of the date:");

name = console.nextLine();

System.out.println("Please enter the day of the date:");

days = console.nextInt();

System.out.println("Please enter the month of the date:");

month = console.nextInt();

System.out.println("Please enter the year of the date:");

year = console.nextInt();

System.out.println("Please enter the era of the date. If the date is in the era before Christ enter B. If the date is in the era after Christ enter A.:");

era = console.next().charAt(0);

My_Date day = new My_Date (days, month, year, era);

}

public class My_Date {

public My_Date ()

{

myYear = 2007;

myMonth = 1;

myDay = 1;

myEra = 'A';

}

public My_Date (int d, int m, int y, char e)

{

if (isValid (d, m, y, e))

{

myDay = d;

myMonth = m;

myYear = y;

if (e == 'a')

e = 'A';

if (e == 'b')

e = 'B';

myEra = e;

}

else

{

myYear = 2007;

myMonth = 1;

myDay = 1;

myEra = 'A';

}

}

private boolean isValid (int d, int m, int y, char e)

{

if (y < 1)

return false;

if (m < 1 || m > 12)

return false;

if (e != 'a' && e != 'A' && e != 'b' && e != 'B')

return false;

if (d < 1 || d > daysInMonth (m, y, e))

return false;

if ((e == 'a' || e == 'A') && m == 9 && y == 1752

&& d > 2 && d < 14)

return false;

return true;

}

private int daysInMonth (int m, int y, char e)

{

switch (m)

{

case 4: case 6: case 9: case 11: return 30;

case 2: return 29;

default: return 31;

}

}

public void print ()

{

}

private int myYear, myMonth, myDay;

private char myEra;

}

}

I don't know why I'am getting this error...I guess it has to do with the constructor My_Date day = new My_Date(days, month, year, era). I don't know if this constructor is right. I need to execute the methods in class My_Date with the parameters that were input from user.

Any Help!

Thank You!!!

JAVI

[2644 byte] By [javi2008a] at [2007-11-26 20:49:38]
# 1

Don't nest My_Date inside of FinalCalculator.

Put them in separate files, for example.

That will fix this problem.

... or change the start of My_Date to:

public static class My_Date {

(Note static!)

But this is a hack. Use two files...

DrLaszloJamfa at 2007-7-10 2:13:41 > top of Java-index,Java Essentials,New To Java...
# 2
Dukes, please.
DrLaszloJamfa at 2007-7-10 2:13:41 > top of Java-index,Java Essentials,New To Java...
# 3
Mind to tell which line the error is? Seriously I can't see a variable 'this' in the program.
Icycoola at 2007-7-10 2:13:41 > top of Java-index,Java Essentials,New To Java...
# 4
The error was here:My_Date day = new My_Date (days, month, year, era);Can you see it?
DrLaszloJamfa at 2007-7-10 2:13:41 > top of Java-index,Java Essentials,New To Java...
# 5
Dukes, please. I found your error and gave two different solutions.
DrLaszloJamfa at 2007-7-10 2:13:41 > top of Java-index,Java Essentials,New To Java...