We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

Drop_of_Rain
Drop_of_Rain asked
on
Medium Priority
1,233 Views
Last Modified: 2006-11-17
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);
      }
}

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
You need to make sure current dir part of classpath

java -classpath .;%CLASSPATH% AudioTest

Author

Commented:
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
CERTIFIED EXPERT
Top Expert 2016

Commented:
I don't know BlueJ, but you need to be able to load AudioTest and AudioConcat, so they must be on the classpath
CERTIFIED EXPERT
Top Expert 2016

Commented:
This usually translates as the classes being part of your project with IDEs

Author

Commented:
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?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Are there any packages involved?

Author

Commented:
This was the error I got running this from the IDE

ClassNotFoundException
MixingAudioInputStream (in java.net.URL ClassLoader

Author

Commented:
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);
      }
}

Author

Commented:
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);
      }
}
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I have ran into package problems, with imported classes to make the program work. For this time I am going to let this go!
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
I'd suggest you put all your classes into a package.

Author

Commented:
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?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
just put the jars in your JRE/JDK's respective "ext" directories.

Author

Commented:
What is the "ext" directories. I looked in the JDK one!

Author

Commented:
I HAVE THIS DIRECTORY j2sdk1.4.2
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
you just need to include those import statements in your code whenever you a class uses them.

Author

Commented:
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.?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I increased the points because this was such a long question.

Thanks everyone, it works and sounded fantastic.
Christopher

Author

Commented:
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.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
:)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.