Why a "private static" is not seen in a method?
        Posted  
        
            by Roman
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Roman
        
        
        
        Published on 2010-04-17T09:11:19Z
        Indexed on 
            2010/04/17
            9:23 UTC
        
        
        Read the original article
        Hit count: 420
        
I have a class with the following declaration of the fields:
public class Game {
private static String outputFileName;
....
}
I set the value of the outputFileName in the main method of the class.
I also have a write method in the class which use the outputFileName. I always call write after main sets value for outputFileName. But write still does not see the value of the outputFileName. It say that it's equal to null.
Could anybody, pleas, tell me what I am doing wrong?
ADDED As it is requested I post more code:
In the main:
    String outputFileName = userName + "_" + year + "_" + month + "_" + day + "_" + hour + "_" + minute + "_" + second + "_" + millis + ".txt"; 
    f=new File(outputFileName);
        if(!f.exists()){
        try {
            f.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }               
    System.out.println("IN THE MAIN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    System.out.println("------>" + outputFileName + "<------");
This line outputs me the name of the file.
Than in the write I have:
public static void write(String output) {
    // Open a file for appending.
    System.out.println("==========>" + outputFileName + "<============");
        ......
}
And it outputs null.
© Stack Overflow or respective owner