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: Calling a void method into a static void main within same class

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    14
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Calling a void method into a static void main within same class

    I am new to java programming and have bad programming writing skills and in great urge of the need of help.

    I have a program with 6 methods, one method being the static void main
    public class ExceptionHandling{
     
    public void FileNotFound (String fileName){
    }
    ....
     
    public static void main(String[ ] args){
    }
    I just need help in placing FileNotFound into the static void main

    I tried:
    ExceptionHandling fetch = new ExceptionHandling();
    fetch.FileNotFound();
    ...and received the error of FileNotFound(java.lang.string) could not be applied to ()

    I have no idea what to do at all. Checked my textbook with no luck and tried everything my textbook gave examples of. Please help me!
    Last edited by helloworld922; November 15th, 2009 at 09:26 AM.


  2. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Calling a void method into a static void main within same class

    You're trying to call FileNotFound with no arguments, but the method you made always needs to have a String (the filename) passed to it.

    So you should use:

    ExceptionHandling fetch = new ExceptionHandling();
    fetch.FileNotFound("Some String");

    or

    ExceptionHandling fetch = new ExceptionHandling();
    String filename = "filename.txt";
    fetch.FileNotFound(filename);

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    14
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Calling a void method into a static void main within same class

    Thank you, it worked! XD

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Calling a void method into a static void main within same class

    You're welcome :-)

    Glad I could be of assistance.

Similar Threads

  1. could not find the main class
    By Tisofa in forum Object Oriented Programming
    Replies: 1
    Last Post: September 27th, 2009, 02:58 AM
  2. Java Code Help - Calling Method
    By KevinGreen in forum Object Oriented Programming
    Replies: 5
    Last Post: September 18th, 2009, 12:55 AM
  3. adding main method to a code
    By IDK12 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 31st, 2009, 08:52 PM
  4. [SOLVED] Is "Public void closeFile()" a problem in the program for AS-Level computing project
    By muffin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2009, 09:12 PM
  5. [SOLVED] How to call string in another class in java?
    By tazjaime in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 23rd, 2009, 09:31 AM