Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 60
  1. #21
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Nobody in his/her right mind expects to be able to fly an airplane without at least reading the user manual. Why on earth do people expect to build (and use) .jar files without at least reading the appropriate manual/tutorials?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  2. #22
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    http://people.cis.ksu.edu/~schmidt/3....packages.html

    This looks like a tutorial for BlueJ users to make a JAR. That's all I could find in 5 minutes.

    @JosAH, because some people like to fly planes without reading the books? I'm not sure, but I don't recommend it either.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #23
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dark View Post
    http://people.cis.ksu.edu/~schmidt/3....packages.html
    @JosAH, because some people like to fly planes without reading the books? I'm not sure, but I don't recommend it either.
    IMNSHO, kids nowadays have an extremely short attention span, they sit in front of their computers, happily typing away without any knowledge and expect everything to work as they wish; it doesn't even come to their mind that there are (online?) books available that teach them how to do it. They think that reading makes their eyeballs bleed and 'teaching' is a dirty word. There should be a exam (even physical) before people are allowed to use a computer. The threshold is way too low now.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #24
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Agreed, I happen to be an exception to that however. Though I know plenty of people who will quit as soon as they realize they won't get instant gratificaiton.

    However, I think this conversation is a little off topic.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Back to the problem.
    @rajkobie Look in the program code and check that all catch blocks have a printStackTrace call in them to display any errors that occur during execution. Add them where missing and recompile the program and put all the stuff into the jar file. Copy the jar file to a test folder
    Then open a console window, move to the test folder and issue this command:
    java -jar YOURJARFILENAMEHERE.jar

    If there are any error messages shown, copy and paste them 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.
    Last edited by Norm; 05-21-2011 at 05:09 PM.

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

  7. #27
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Obviously we didn't spoonfeed the OP enough about:

    1) how to add files to a jar (i.e. resources the application depends on)
    2) how to use the Class.getResourceAsStream( ... ) method.

    Somehow, someday, someone will spell it out for the OP ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #28
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    thank you so much sir.

  9. #29
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Back to the problem.
    @rajkobie Look in the program code and check that all catch blocks have a printStackTrace call in them to display any errors that occur during execution. Add them where missing and recompile the program and put all the stuff into the jar file. Copy the jar file to a test folder
    Then open a console window, move to the test folder and issue this command:
    java -jar YOURJARFILENAMEHERE.jar

    If there are any error messages shown, copy and paste them 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.
    Here is the error i get:

    Java Code:
    Unable to access jarfile myProg.jar

    myProg is the name of jar file.

    Oh btw i was messing around i typed this in the command promt where the file is

    i typed in command line : java myPorg.jar

    and i got this error

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: myProg/jar
    Caused by: java.lang.ClassNotFoundException: myProg.jar
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: myProg.jar.  Program will exit.
    thought this might be useful

  10. #30
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    The way you're trying to start the JVM it is interpreting "myProg.jar" as a class file where "jar" is its name and "myProg" is its package. Run "java -help" and see how a .jar file is supposed to be run.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Please copy ALL of the contents of the console. You've only copied one or two lines. Need to see all of it, including the command line that you entered and the name of the folder you were in.

  12. #32
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    oh ok
    sorry i think i messed up

    now i get this error

    Microsoft Windows [Version 6.0.6001]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\User>cd Desktop

    C:\Users\User\Desktop>cd TestNew

    C:\Users\User\Desktop\TestNew>java -jar myProg.jar
    java.io.FileNotFoundException: BackgroundMusic.wav (The system cannot find the f
    ile specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at com.sun.media.sound.WaveFileReader.getAudioInputSt ream(Unknown Source
    )
    at javax.sound.sampled.AudioSystem.getAudioInputStrea m(Unknown Source)
    at Sound.<init>(Sound.java:37)
    at MainSwitchBoard.<init>(MainSwitchBoard.java:151)
    at BomberTester.main(BomberTester.java:14)
    Exception in thread "main" java.lang.NullPointerException
    at Sound.startTitleScreenMusic(Sound.java:84)
    at MainSwitchBoard.<init>(MainSwitchBoard.java:167)
    at BomberTester.main(BomberTester.java:14)

    C:\Users\User\Desktop\TestNew>
    I know what this error means

    but i typed in the command line when i created:

    jar cfm myProg.jar manifest.txt *.class *.java *.jpg *.png *.wav *.gif

    I swear i included everything
    Last edited by rajkobie; 05-21-2011 at 06:44 PM.

  13. #33
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    FileNotFoundException: BackgroundMusic.wav (The system cannot find the file specified)
    Where is the file listed in the above error message?

    Sound.java:37)
    Look at line 37 in the Sound class to see how the program is trying to read the file.

  14. #34
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by rajkobie View Post
    oh ok
    sorry i think i messed up

    now i get this error



    I know what this error means

    but i typed in the command line when i created:

    jar cfm myProg.jar manifest.txt *.class *.java *.jpg *.png *.wav *.gif

    I swear i included everything
    You may have put that .wav file in your .jar file but now it isn't a file anymore, it's a resource as everything else in your .jar file. Resources can be opened by the method Class.getResourceAsStream( ... ) not as a file as your code tried to. Read the API documentation for that method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #35
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    this is how i read the sound

    private AudioInputStream audIn;
    private File flSoundFile;
    private Clip clpMyBackgroundMusic;

    flSoundFile = new File ( "BackgroundMusic.wav" );
    audIn = AudioSystem.getAudioInputStream ( flSoundFile ); //This is line 37
    clpMyBackgroundMusic = AudioSystem.getClip ( );
    clpMyBackgroundMusic.open ( audIn );

    and i later on in method open it

    Also,

    I store the music, images everything on one big folder. they are all in one folder ( the classes java files sound images everything )

  16. #36
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  17. #37
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    As JosAH has pointed out, if you want to read "files" that are inside of a jar file with the classes that are executing from that jar file, you can NOT use the File class. You must use a class that will read the "file" from within the jar file.
    Look at the getAudioInputStream method and see if takes other arguments that you could supply by using the
    Class.getResourceAsStream( ... ) method.
    Last edited by Norm; 05-21-2011 at 07:37 PM.

  18. #38
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    I doubt that the sound , immages are in the jar file

    Again when i created it i did say add *.jpg ... add everything i use

    How do i check if i have the files?

    If i do not have then how do i add them to the jar file?

  19. #39
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    how do i add them to the jar file?
    See YOUR post #32.

    You can view the contents of the jar file by using a zip file utility. An easy way is to rename the jar file by adding .zip to its name and then opening it with a zip file utility.

  20. #40
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    This is how i load my images:

    Image myImage = new ImageIcon ( "Hi.gif" ).getImage ( );

    Then i draw this using a graphics2d object's drawImage ( myImage , x ,y , null );

    I tried to load images and sound using class.getResourceAsStream ( ... ) but i cant put it into an imageicon and draw on the screen.

    How should i fix this?
    Last edited by rajkobie; 05-22-2011 at 03:21 AM.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Why isnt this working?
    By GoingThroAPhase in forum New To Java
    Replies: 4
    Last Post: 04-03-2010, 03:36 AM
  2. My rotate 2d pos method isnt working correctly..
    By Addez in forum New To Java
    Replies: 5
    Last Post: 12-01-2009, 10:04 AM
  3. Replies: 6
    Last Post: 11-12-2009, 11:50 AM
  4. BlueJ arrow missing betwen two classes
    By jboy in forum New To Java
    Replies: 2
    Last Post: 10-29-2009, 01:42 PM
  5. Replies: 1
    Last Post: 04-17-2008, 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •