Directory folder - null pointer exception on MAC only

    Apr 09 2009 | 10:36 pm
    import com.cycling74.jitter.JitterMatrix;
    import com.cycling74.jitter.JitterObject;
    public class MoviesManager extends Thread {
    	 * Constant  - Path to the folder which contains the video
    	private static final String PATH_FOLDER = "afp://";
    	private int nbMovies;
    	private File directory;
    	private JitterMatrix jmOut;
    	public MoviesManager(JitterMatrix jmOut) {
    		directory = new File(PATH_FOLDER);
    		this.jmOut = jmOut;
    	 * Method  - Free peers
    	 * @param m
    	 *            movies
    	private void freePeers(MaxVideo[] m) {
    		if (m != null)
    			for (int i = m.length-1; i >= 0; i++) {
    	/* (non-Javadoc)
    	 * @see java.lang.Thread#run()
    	public void run() {;
    		File[] files;
    		//while (true) {
    			files = directory.listFiles();
    			nbMovies = files.length;
    			// If the videos' array is not created
    			if (MaxTest.videos == null) {
    				MaxTest.videos = new MaxVideo[nbMovies];
    			else {
    				// Free the object
    				// Reinitialize the array;
    				MaxTest.videos = new MaxVideo[nbMovies];
    			for (int i = 0; i < nbMovies; i++) {
    				// Create the video object
    				MaxTest.videos[i] = new MaxVideo(new JitterObject(""), this.jmOut);
    				System.out.println("file : "+files[i].getName());
    				MaxTest.videos[i].getMovie().send("autostart", 0);
    			// Wait 5 seconds before check the folder a new time
    I have a java null pointer exception on the line "files = directory.listFiles();" : so I find that come fron "nbMovies = files.length;" but I don't know why it is not working. The path is right !
    The same class work perfectly on windows !
    Thanks for help me.

    • Apr 15 2009 | 6:36 am
      I stripped it down to some simple code that I ran outside of Max:
      public class AfpFileTest {
      	public static void main(String args[]) {
      		File directory = new File("afp://");
      		File[] files = directory.listFiles();
      		System.out.println("Found " + files.length + " files");
      I can't get it to work on either OS X or Windows. NullPointerException in both cases. directory.listFiles() is returning null. If you check the javadocs: it says: "Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs."
      I'm fairly certain this is because you are using the afp:// protocol. I'm surprised it works for you on Windows, maybe you installed some sort of special library to support it? I wouldn't expect Apple's proprietary remote network file system to work out-of-the-box with Java's standard File API...
      I'd suggest you find an alternative way to access the files. I am not familiar with afp so I don't have any specific suggestions. But maybe there is a way to mount the remote network server so that it looks like a normal local hard drive to Java. Otherwise, I'd see if it's possible to use http or ftp instead. Those are much more common open protocols and should be easier to get working with Java.
    • Apr 15 2009 | 7:06 am
      I tried with a local path on both : - windows : worked (local path) - mac : never worked (local and server path)
      To get it work on windows, you have to replace the path at 2 places : when I create the directory object and when I am looking for all files in the directory.
      here :
      File directory = new File(_PATH_);
      and here :
      MaxTest.videos[i].getMovie().send("read", _PATH_+files[i].getName());
    • Apr 15 2009 | 4:17 pm
      carob wrote on Wed, 15 April 2009 00:06I tried with a local path on both : - windows : worked (local path) - mac : never worked (local and server path)
      That's weird. Local paths should be ok. What are you using for the local path?
    • Apr 15 2009 | 4:24 pm
      carob wrote on Wed, 15 April 2009 08:06
      MaxTest.videos[i].getMovie().send("read", _PATH_+files[i].getName());
      Well, you don't really want to do this... look at the File constructor with parent and child arguments:
      It may not solve your problem but it is a lot neater.
      Btw, the forum software is broken, so you'll have to select the entire URL manually.
    • Apr 15 2009 | 6:27 pm
      Local path work but only for windows not for mac
    • Apr 15 2009 | 9:02 pm
      carob wrote on Wed, 15 April 2009 11:27Local path work but only for windows not for mac
      My guess is you are not forming the path correctly on Mac. Try calling file.exists() after creating the File object and make sure it's true...
      Sorry if I'm stating the obvious, but you realize paths will look different on Windows and Mac? So something like "C:Program FilesMax5" on Windows is going to be something like "/Applications/Max5" on Mac.
      Since you probably need to use different paths you can do something like:
      if(System.getProperty("").contains("Windows")) {
         // set windows path
      } else {
         // set mac path
      It's also possible to find files relative to some known file in the Max installation (like your patcher file if it's on the Max search path). This might be a better solution. I can provide more details if needed.
    • Apr 16 2009 | 6:16 pm
      My path was wrong : I have to use the local one and no the server one.
      Thank you for your help.