Solved

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

Posted on 2004-04-13
27
941 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);
      }
}

0
Comment
Question by:Drop_of_Rain
  • 13
  • 7
  • 4
  • +1
27 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10814374
You need to make sure current dir part of classpath

java -classpath .;%CLASSPATH% AudioTest
0
 

Author Comment

by:Drop_of_Rain
ID: 10814423
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10814481
I don't know BlueJ, but you need to be able to load AudioTest and AudioConcat, so they must be on the classpath
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 10814510
This usually translates as the classes being part of your project with IDEs
0
 

Author Comment

by:Drop_of_Rain
ID: 10814588
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?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10814681
Are there any packages involved?
0
 

Author Comment

by:Drop_of_Rain
ID: 10814805
This was the error I got running this from the IDE

ClassNotFoundException
MixingAudioInputStream (in java.net.URL ClassLoader
0
 

Author Comment

by:Drop_of_Rain
ID: 10814810
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);
      }
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10814831
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);
      }
}
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 10817840
your code could be simplified as:

public class AudioTest
{
     public static void main(String[] args)
     {
          AudioConcat.main(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
                    });
     }
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10820408
I have ran into package problems, with imported classes to make the program work. For this time I am going to let this go!
0
 
LVL 92

Expert Comment

by:objects
ID: 10820440
I'd suggest you put all your classes into a package.
0
 

Author Comment

by:Drop_of_Rain
ID: 10820533
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 10820549
just put the jars in your JRE/JDK's respective "ext" directories.
0
 

Author Comment

by:Drop_of_Rain
ID: 10820576
What is the "ext" directories. I looked in the JDK one!
0
 

Author Comment

by:Drop_of_Rain
ID: 10820601
I HAVE THIS DIRECTORY j2sdk1.4.2
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 10820699
it'll probably be:

j2sdk1.4.2/jre/lib/ext
0
 

Author Comment

by:Drop_of_Rain
ID: 10820727
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 10820754
you just need to include those import statements in your code whenever you a class uses them.
0
 

Author Comment

by:Drop_of_Rain
ID: 10820777
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.?
0
 
LVL 92

Expert Comment

by:objects
ID: 10820862
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
0
 
LVL 9

Assisted Solution

by:mmuruganandam
mmuruganandam earned 250 total points
ID: 10821609
Keep the java-getopt-1.0.928981.jar and AudioConcat in the classpath to get it work.
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 250 total points
ID: 10821923
Let say,
your java-getopt-1.0.928981.jar is in c:\test

your AudioConcat class file is at your working directory.


Then
javac -classpath .;c:\test\java-getopt-1.0.928981.jar AudioTest.java



Regards,
Muruga
0
 

Author Comment

by:Drop_of_Rain
ID: 10821981
I increased the points because this was such a long question.

Thanks everyone, it works and sounded fantastic.
Christopher
0
 

Author Comment

by:Drop_of_Rain
ID: 10822012
Thanks all you guys you are the greatest,
Christopher
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10822022
It is a great feeling to me that you have made it atlast.  All the best to you.
0
 
LVL 92

Expert Comment

by:objects
ID: 10828259
:)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question