(Java) package does not exist

Discussion in 'Mac Programming' started by Avicenna, Mar 18, 2011.

  1. Avicenna, Mar 18, 2011
    Last edited by a moderator: Mar 18, 2011

    Avicenna macrumors member

    Joined:
    Jul 16, 2009
    #1
    I am new to Java. I am trying to use a class (AudioFile) that is located in the folder org ->jaudiotagger -> audio. My main class is running from the same directly as the folder org is located in. I am importing the package but when I try to compile it gives me package does not exist error. You can see the entire layout of the files, my Main class and the error produced below:

    [​IMG]

    Thanks!
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    Do this
    Code:
    cd ~/Desktop/MP3AlbumArt
    
    before doing this
    Code:
    javac Main.java
    
    Then you'll be able to successfully run it too with
    Code:
    java Main
    
     
  3. Avicenna thread starter macrumors member

    Joined:
    Jul 16, 2009
    #3
    Hey thanks for the input but it's still not working. It tells me that it could not find the symbol audio file. But if I address AudioFile as org.jaudiotagger.audio.AudioFile then it works, but this name is too long. Is there a way I can just call it AudioFle?

    I am importing org.jaudiotagger.*;
     
  4. Mac Player macrumors regular

    Joined:
    Jan 19, 2006
    #4
    This,

     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    That's not what your code says. This is your code:
    Code:
    [COLOR="Red"]import org.jaudiotagger.audio;
    [/COLOR]
    public class Main {
    
      public static void main(String[] args) {
    
        AudioFile f = new AudioFile();
    
      }
    }
    
    The red-hilited statement imports a single class named 'audio' located in the package org.jaudiotagger. Since no such class exists, the import fails.


    Fix your import statement and the reference to the AudioFile class will work. The import should be:
    Code:
    import org.jaudiotagger.audio.*;
    
    Sub-packages or super-packages must be imported separately. Imports are not hierarchical. The ".*" only imports classes in that single package. It does not import any sub-packages or super-packages. For example, to get the FileConstants class you need one of these:
    Code:
    import org.jaudiotagger.FileConstants;
    import org.jaudiotagger.*;
    

    For future reference, posting a giant picture is a poor way to show code. Post actual code, as copied and pasted text. Do not post pictures of code.

    You should copy and paste the text of error messages, too, rather than pictures of them.
     

Share This Page