Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Generating a Batch File - Static Method Error

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Generating a Batch File - Static Method Error

    Hey guys, I'm clearly new here, scoured the internet for a solution to my problem but could not find one, so I figured I'd make a post on the first forum I found, which is this one! (congratulations).

    Anyways:

    import java.io.*;
     
    public class UpdateACL {
        private FileOutputStream fos;
        private DataOutputStream dos;
    	private static String projectName = "";
    	private static String projectPath = "xcopy C:\\st22615_SharedTools_mainline_intg\\vobs\\sharedtools\\src\\ClearCase\\triggers\\acl\\project\\" +
    						  projectName + "\\* \\0\\cm\\acl\\project\\" + projectName + "/y /r /s /i" + "pause";
     
     
        public void ChangeACL() throws FileNotFoundException, IOException {
     
            File file;
            file = new File("C:\\samplenote.bat");
            fos=new FileOutputStream(file);
            dos=new DataOutputStream(fos);
            dos.writeBytes(projectPath);
        }
     
    	public static void main(String args[]){
    	try{
    		System.out.print("Enter the project name:");
    		InputStreamReader converter = new InputStreamReader(System.in);
    		BufferedReader in = new BufferedReader(converter);
    		projectName = in.readLine();
     
    		ChangeACL(); //Calling this method gives non-static method call in static context error
     
    } catch (FileNotFoundException e) {
        System.err.println("FileNotFoundException: " + e.getMessage());
     
    } catch (IOException e) {
        System.err.println("Caught IOException: " + e.getMessage());
    }
    }
    }

    I'm basically trying to generate a batch file that will hold that string, that I can run immediately after it is generated...however I cannot call Change.ACL(), even though it is in the same class? Confusing...

    If anyone could provide insight on this that would be great.

    Cheers.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Generating a Batch File - Static Method Error

    I cannot call Change.ACL()
    Please post the full text of the compiler's error message.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: Generating a Batch File - Static Method Error

    Change the code to be either:

    public static void ChangeACL() throws FileNotFoundException, IOException {

    (notice the static declaration) or

    UpdateACL updateACL = new UpdateACL();
     
    updateACL.ChangeACL();

    in your main() method.
    Need Java help? Check out the HotJoe Java Help forums!

  4. The Following User Says Thank You to stdunbar For This Useful Post:

    Stroypet (May 17th, 2012)

  5. #4
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Generating a Batch File - Static Method Error

    Awesome, thanks stdunbar! It all makes sense...

Similar Threads

  1. Replies: 1
    Last Post: April 3rd, 2012, 06:32 AM
  2. non-static method cannot be referenced from a static context
    By Kaltonse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2010, 07:51 PM
  3. calling a java a class connected to derby from a batch file
    By Reem in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 03:01 PM
  4. Error using public static double Method
    By stommy989 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 13th, 2010, 03:01 PM
  5. Replies: 10
    Last Post: September 6th, 2010, 04:48 PM

Tags for this Thread