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

Thread: How to create your own packages?

  1. #1
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default How to create your own packages?

    Hello!

    I'm following a tutorial that is using eclipse but i use notepad++ to code. I know eclipse is better but I feel familiar with notepad++ and the cmd prompt. What I was wondering is how do you create your own packages and where do you put them. I have a package called jg.misfit.game.graphics and I put it in C:\Program Files\Java\jg\misfit\game\graphics. So far the file game has one class in it and the file graphics has one class in it. Did i put my package in the correct location, how do I make a package using the cmd prompt and should I just use eclipse? The reason I'm asking is because the class in game can't find the class in graphics when I compile it.

    javac: file not found Render.java
    Usage: javac <options> <source files>

    Thank you to all who respond!

    lil_misfit


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: How to create your own packages?

    Packages are just folder structures (well, they are more than that, but digging deeper is unnecessary).
    You also need to specify the package for each class at the top (before the imports). Like:
    package jg.misfit.game.graphics;

    I would recommend eclipse, since it will do a lot of project management for you.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    lil_misfitss (June 28th, 2014)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create your own packages?

    What folder did you issue the javac command in? You could be in the same one with the .java file. You'll need to set the classpath to point to the folder containing the package for the other classes.
    Can you copy the contents of the command prompt window and paste it here?
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    lil_misfitss (June 28th, 2014)

  6. #4
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: How to create your own packages?

    Okay so I think the compiler is finding the Render.java file but now this appears when compiling Game.java:

    C:\Program Files\Java\jg\misfit\game>javac Game.java
    Game.java:9: error: cannot access Render
    import graphics.Render;
    ^
    bad source file: .\graphics\Render.java
    file does not contain class graphics.Render
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.


    Thank you guys for replying!
    lil_misfit [COLOR="Silver"]

    --- Update ---

    So in the top of Game.java's code I put

    package jg.misfit.game;

    then in Render.java's code I put

    package jg.misfit.game.graphics;

    Is this correct?

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create your own packages?

    The classpath needs to point to the folder that contains the package folder: graphics
    Where is the graphics folder located?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #6
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: How to create your own packages?

    The graphics folder is in the game folder: jg.misfit.game.graphics.
    So how do i change the classpath to include graphics folder?

  9. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to create your own packages?

    C:\Program Files\Java\jg\misfit\game>javac Game.java
    For that command, the classpath should point to the current folder: game
    so if graphics is in game, it should be on the classpath

    The java files in the graphics folder should be in package graphics.


    Can you make some small complete programs that compile and execute and have just the package, import statements and a new statement in the main() method. Have the other test programs without the main() print a message in their constructors.
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    lil_misfitss (July 4th, 2014)

  11. #8
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: How to create your own packages?

    Sorry I haven't responded, been away from programming a bit. I will try that little "exercise" and see if I can get packages working! Thanks for all the help Norm the SUPER MODERATOR!

    lil_misfit

Similar Threads

  1. Problem with packages.
    By fkmk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2014, 05:18 PM
  2. Trying to Figure out Packages
    By tyeeeee1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 18th, 2013, 01:33 PM
  3. packages
    By Spidey1980 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 6th, 2011, 06:45 PM
  4. Problem with Packages
    By pirezas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 12th, 2010, 03:41 PM
  5. importing packages..
    By chronoz13 in forum Java IDEs
    Replies: 4
    Last Post: November 23rd, 2009, 05:49 PM