Link to home
Start Free TrialLog in
Avatar of Drop_of_Rain
Drop_of_Rain

asked on

Exception in thread "main" java.lang.NoClassDefFoundError: AudioTest.java

What could cause this? Here is the code


public class AudioTest
{
      public static void main(String[] args)
      {
            args =
                  new String[] {
                        "-c",  // concatenation mode
                        "-o",  // output file specified
                        "c:/test/test.wav", // output file
                        "c:/test/wav/kp1.wav", // input file 1
                        "c:/test/wav/kp2.wav", // input file 2
                        "c:/test/wav/kp3.wav", // input file 3
                        "c:/test/wav/kp4.wav" // input file 4
                        };

            AudioConcat.main(args);
      }
}

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to make sure current dir part of classpath

java -classpath .;%CLASSPATH% AudioTest
Avatar of Drop_of_Rain
Drop_of_Rain

ASKER

Could you explain that better please How do I do that, I haven't used the command line I use A Development Program named BlueJ it takes care of a lot of this
I don't know BlueJ, but you need to be able to load AudioTest and AudioConcat, so they must be on the classpath
This usually translates as the classes being part of your project with IDEs
I am very new to this I have never ran a program from the commandline where there is multiable classes involved like this. Even the books that I have used delt with only one at a time. I will be learning about that soon.

so they must be on the classpath

If you could give me a simple example maybe I could get it?
Are there any packages involved?
This was the error I got running this from the IDE

ClassNotFoundException
MixingAudioInputStream (in java.net.URL ClassLoader
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.sound.sampled.*;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.BooleanControl;

public class SequenceAudioInputStream extends AudioInputStream
{

      private static final boolean DEBUG = true;
      private List m_audioInputStreamList;
      private int m_nCurrentStream;

      public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams)
      {
            super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED);
            m_audioInputStreamList = new ArrayList(audioInputStreams);
            m_nCurrentStream = 0;
      }

      public void addAllAudioInputStream(ListOfFiles iterator) throws UnsupportedAudioFileException, IOException
      {
            while (iterator.hasMoreElements())
            {
                  addAudioInputStream(AudioSystem.getAudioInputStream((InputStream)iterator.nextElement()));
            }
      }
      
      private boolean addAudioInputStream(AudioInputStream audioStream)
      {
            if (DEBUG)
            {
                  out("SequenceAudioInputStream.addAudioInputStream(): called.");
            }

            if (!getFormat().matches(audioStream.getFormat()))
            {
                  if (DEBUG)
                  {
                        out("SequenceAudioInputStream.addAudioInputStream(): audio formats donot match, trying to convert.");
                  }

                  AudioInputStream asold = audioStream;
                  audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);
                  if (audioStream == null)
                  {
                        out("### SequenceAudioInputStream.addAudioInputStream(): could notconvert.");
                        return false;
                  }

                  if (DEBUG)
                  {
                        out(" converted");
                  }
            }

            synchronized (m_audioInputStreamList)
            {
                  m_audioInputStreamList.add(audioStream);
                  m_audioInputStreamList.notifyAll();
            }

            if (DEBUG)
            {
                  out("SequenceAudioInputStream.addAudioInputStream(): enqueued " + audioStream);
            }
            return true;
      }

      private AudioInputStream getCurrentStream()
      {
            return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
      }

      private boolean advanceStream()
      {
            m_nCurrentStream++;
            boolean bAnotherStreamAvailable = (m_nCurrentStream < m_audioInputStreamList.size());
            return bAnotherStreamAvailable;
      }

      public long getFrameLength()
      {
            long lLengthInFrames = 0;
            Iterator streamIterator = m_audioInputStreamList.iterator();
            while (streamIterator.hasNext())
            {
                  AudioInputStream stream = (AudioInputStream) streamIterator.next();
                  long lLength = stream.getFrameLength();
                  if (lLength == AudioSystem.NOT_SPECIFIED)
                  {
                        return AudioSystem.NOT_SPECIFIED;
                  }
                  else
                  {
                        lLengthInFrames += lLength;
                  }
            }
            return lLengthInFrames;
      }

      public int read() throws IOException
      {
            AudioInputStream stream = getCurrentStream();
            int nByte = stream.read();
            if (nByte == -1)
            {
                  /*
                  The end of the current stream has been signaled.
                  We try to advance to the next stream.
                  */
                  boolean bAnotherStreamAvailable = advanceStream();
                  if (bAnotherStreamAvailable)
                  {
                        /*
                        There is another stream. We recurse into this method
                        to read from it.
                        */
                        return read();
                  }
                  else
                  {
                        /*
                        No more data. We signal EOF.
                        */
                        return -1;
                  }
            }
            else
            {
                  /*
                  The most common case: We return the byte.
                  */
                  return nByte;
            }
      }

      public int read(byte[] abData, int nOffset, int nLength) throws IOException
      {
            AudioInputStream stream = getCurrentStream();
            int nBytesRead = stream.read(abData, nOffset, nLength);
            if (nBytesRead == -1)
            {
                  /*
                  The end of the current stream has been signaled.
                  We try to advance to the next stream.
                  */
                  boolean bAnotherStreamAvailable = advanceStream();
                  if (bAnotherStreamAvailable)
                  {
                        /*
                        There is another stream. We recurse into this method
                        to read from it.
                        */
                        return read(abData, nOffset, nLength);
                  }
                  else
                  {
                        /*
                        No more data. We signal EOF.
                        */
                        return -1;
                  }
            }
            else
            {
                  /*
                  The most common case: We return the length.
                  */
                  return nBytesRead;
            }
      }

      public long skip(long lLength) throws IOException
      {
            throw new IOException("skip() is not implemented in class SequenceInputStream.Mail < Matthias.Pfisterer @ web.de > if you need this feature.");
      }

      public int available() throws IOException
      {
            return getCurrentStream().available();
      }

      public void close() throws IOException
      {
            // TODO: should we close all streams in the list?
      }

      public void mark(int nReadLimit)
      {
            throw new RuntimeException("mark() is not implemented in class SequenceInputStream.Mail < Matthias.Pfisterer @ web.de > if you need this feature.");
      }

      public void reset() throws IOException
      {
            throw new IOException("reset() is not implemented in class SequenceInputStream.Mail < Matthias.Pfisterer @ web.de > if you need this feature.");
      }

      public boolean markSupported()
      {
            return false;
      }

      private static void out(String strMessage)
      {
            System.out.println(strMessage);
      }
}
It came from this this was highlighted    AudioConcat.main(args);



public class AudioTest
{
      public static void main(String[] args)
      {
            args =
                  new String[] {
                        "-c",  // concatenation mode
                        "-o",  // output file specified
                        "c:/test/test.wav", // output file
                        "c:/test/wav/kp1.wav", // input file 1
                        "c:/test/wav/kp2.wav", // input file 2
                        "c:/test/wav/kp3.wav", // input file 3
                        "c:/test/wav/kp4.wav" // input file 4
                        };

            AudioConcat.main(args);
      }
}
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have ran into package problems, with imported classes to make the program work. For this time I am going to let this go!
I'd suggest you put all your classes into a package.
The problem I had with that was this:   import org.tritonus.share.sampled.TConversionTool; in one of the files this in another:  import gnu.getopt.Getopt;. I got the jar files for these but am unsure of what to do. I know I have to create a package but how with these different names in import?
just put the jars in your JRE/JDK's respective "ext" directories.
What is the "ext" directories. I looked in the JDK one!
I HAVE THIS DIRECTORY j2sdk1.4.2
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok I got them in there now what, how do I handle:

import org.tritonus.share.sampled.TConversionTool; in one of the files this in another:  import gnu.getopt.Getopt;.  I know I have to create a package but how with these different names in import?
you just need to include those import statements in your code whenever you a class uses them.
I didn't mean that, now that those jar files are in the java directory the imports will work as they are named. Ok does the package need to starte from the root c:\\starting package folder\next folder\etc.?
When yusing packages you need to make sure that your directory structure mirrors your package structure and the the parent directory of your package is part of your classpath.

eg. if your package is au.com.objects, and your classes are stored in /project/classes/au/com/objects
then your classpath would nbeed to include /project/classes

http://www.mindprod.com/jgloss/classpath.html
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I increased the points because this was such a long question.

Thanks everyone, it works and sounded fantastic.
Christopher
Thanks all you guys you are the greatest,
Christopher
It is a great feeling to me that you have made it atlast.  All the best to you.