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 2 of 2

Thread: Regarding to run a package program in java

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Regarding to run a package program in java

    whenever i typed a package program i get an error message "the package does not exist". so please help me to run this program


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,310
    My Mood
    Mellow
    Thanks
    253
    Thanked 780 Times in 765 Posts

    Default Re: Regarding to run a package program in java

    Programs in packages are required to be saved in a directory structure that matches the package structure. For example, start with s simple program, like:
    package simpleprogram;
     
    public class TestClass2
    {
        public static void main( String[] args )
        {
            System.out.println( "In main() method." );
        }
     
    }
    Save the file to a subdirectory of your typical source file location called simpleprogram (the same as the package name).

    Change to the directory simpleprogram and compile the source file using the command:

    $ javac TestProgram2.java

    (The '$ ' is a prompt, not part of the command.)

    If you try and run the program while in that directory with the command java TestProgram2, you'll get an error. However, if you move up one level in the directory structure and then run the program using the command:

    $ java simpleprogram/TestClass2

    it will work.

    If you have trouble following these directions and making it work, come back and describe exactly what you've done with any error messages you get.

Similar Threads

  1. When I run my program, it says error: java.lang.NullPointerException
    By ProgrammerNoobE in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 28th, 2013, 05:08 PM
  2. When I run my program, it says error: java.lang.NullPointerException
    By ProgrammerNoobE in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 28th, 2013, 09:19 AM
  3. Replies: 8
    Last Post: February 12th, 2013, 05:45 AM
  4. How would you run jar file with a java program?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 31st, 2012, 03:03 PM
  5. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 11:04 AM