import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
public class Swipe_In
{
public String DTStart; //Swipe in Date Time
public static void main()
{
//Swipe_In demo = new Swipe_In();
System.out.println("Press 1 for Swipe In ...");
Scanner flagIn = new Scanner(System.in);
int checkIn = flagIn.nextInt();
if (checkIn==1)
{
System.out.println("You have successfully Swiped In...");
//current(Swipe In) Date & Time as DTStart
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
DTStart = dateFormat.format(cal.getTime()); //acquires the current time and date...
System.out.println("Swiped In @ " + DTStart); // <--error here ...
}
else
{
System.out.println("Swipe In Unsuccessful ...Try Again");
}
}
}
I have got 2 questions on the above class...
1) I get an error "Cannot make a static reference to the non-static field DTStart" wherever i use DTStart in the main
method....What's causing this error? and How do i fix it for good?
2) public String DTStart;
Once i get the current date & time assigned to the above DTStart String in the main method i cannot use the updated
value of DTStart in any other class. In another class i wanna create an instance(object) of this Swipe_In class with
DTStart assigned to the current time(as in its main method)..I tried but the object's DTStart gets assigned to null.((
How do i achieve this? Hope i haven't twisted my last question too much..
I would really appreciate your time and effort if u can help me with my prob....Thank u ...)