Results 1 to 2 of 2
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Post Problems with returning a TargetDataLine object..

    Hi!
    Im trying to make a method that should return a TargetDataLine object given a string.
    Im a bit upset because what I'v learned is that targetlines are speakers etc.
    Sourcelines are microphones etc.
    So why do I need a targetline to get sound from my microphone?!

    Anyways, to accuire a list of options of targetlines I use the following method:

    PHP Code:
    public static ArrayList<String> getChannels() {
    		ArrayList<String> list = new ArrayList<String>();
    		try{
    			Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
    			for (Mixer.Info info : mixerInfos) {
    				Mixer m = AudioSystem.getMixer(info);
    				Line.Info[] lineInfos = m.getSourceLineInfo();
    				for (Line.Info lineInfo : lineInfos) {
    					list.add(info.getName());
    					
    				}
    
    	
    			}
    		} catch (Exception e){
    			e.printStackTrace();
    		}
    		return list;
    		
    	}
    Then using a combobox I select of of those objects and send it to the following method
    to accuire my targetdataline.

    PHP Code:
    private static TargetDataLine getLine(String lineName) {
    		TargetDataLine line = null;
    		
    		try{
    			Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
    			for (Mixer.Info info : mixerInfos) {
    				Mixer m = AudioSystem.getMixer(info);
    				Line.Info[] lineInfos = m.getTargetLineInfo();
    				for (Info lineInfo : lineInfos) {
    					if (info.getName().contains(lineName)){
    						Info[] info2 = m.getTargetLineInfo(lineInfo);
    						
    						line = (TargetDataLine) m.getLine(lineInfo);//	line = m.getLine(lineInfo);
    					}
    				}
    				
    	
    			}
    		} catch (Exception e){
    			e.printStackTrace();
    		}
    		return  line;
    	}
    And I get the error:
    Java Code:
    java.lang.NullPointerException
    java.lang.ClassCastException: com.sun.media.sound.PortMixer$PortMixerPort cannot be cast to javax.sound.sampled.TargetDataLine
    at this line:
    Java Code:
    line = (TargetDataLine) m.getLine(lineInfo);//	line = m.getLine(lineInfo);

    Any idea of what could be wrong?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default

    ClassCastException: com.sun.media.sound.PortMixer$PortMixerPort cannot be cast to javax.sound.sampled.TargetDataLine
    Is the value returned by the method the correct data type? The JVM does not think so.

    What does the API doc say is returned by the method?

Similar Threads

  1. Struts action form not returning object
    By niteangell21 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 02-08-2011, 05:50 PM
  2. Returning an object
    By dom12 in forum New To Java
    Replies: 3
    Last Post: 11-02-2010, 11:30 AM
  3. Replies: 1
    Last Post: 08-28-2010, 01:27 PM
  4. Method, returning reference to an object
    By Saletra in forum New To Java
    Replies: 3
    Last Post: 08-23-2010, 08:22 PM
  5. returning an object from a method
    By bigj in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 12:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •