3 Replies - 501 Views - Last Post: 02 November 2017 - 01:52 PM Rate Topic: -----

#1 Sciuriware  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 17-August 13

JAVA9 error: can not instrument ...

Posted 01 November 2017 - 01:27 AM

Hi all,
I used to play sounds by the Applet class, deprecated in JAVA9.
So I got me an example that works on 8 and 9 both to adapt.
But, I found that while the sample program seems to work well,
on JAVA 9 there is a flood of nonfatal error messages I can't understand:

Could not instrument class Play: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:550)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1007)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:801)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at java.base/sun.launcher.LauncherHelper.loadMainClass(LauncherHelper.java:654)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:551)

As the source compiles without warnings (deploying ECLIPSE 4.8M3a) I wonder what I forgot.
Source: (attaching failed):
import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

/**
 * This is an example program that demonstrates how to play back an audio file
 * using the Clip in Java Sound API.
 * @author www.codejava.net
 *
 */
public class Play implements LineListener {
	
	/**
	 * this flag indicates whether the playback completes or not.
	 */
	boolean playCompleted;
	
	/**
	 * Play a given audio file.
	 * @param audioFilePath Path of the audio file.
	 */
	void play(String audioFilePath) {
		File audioFile = new File(audioFilePath);

		try {
			AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);

			AudioFormat format = audioStream.getFormat();

			DataLine.Info info = new DataLine.Info(Clip.class, format);

			Clip audioClip = (Clip) AudioSystem.getLine(info);

			audioClip.addLineListener(this);

			audioClip.open(audioStream);
			
			audioClip.start();
			
			while (!playCompleted) {
				// wait for the playback completes
				try {
					Thread.sleep(1000);
				} catch (InterruptedException ex) {
					ex.printStackTrace();
				}
			}
			
			audioClip.close();
			
		} catch (UnsupportedAudioFileException ex) {
			System.out.println("The specified audio file is not supported.");
			ex.printStackTrace();
		} catch (LineUnavailableException ex) {
			System.out.println("Audio line for playing back is unavailable.");
			ex.printStackTrace();
		} catch (IOException ex) {
			System.out.println("Error playing the audio file.");
			ex.printStackTrace();
		}
		
	}
	
	/**
	 * Listens to the START and STOP events of the audio line.
	 */
	@Override
	public void update(LineEvent event) {
		LineEvent.Type type = event.getType();
		
		if (type == LineEvent.Type.START) {
			System.out.println("Playback started.");
			
		} else if (type == LineEvent.Type.STOP) {
			playCompleted = true;
			System.out.println("Playback completed.");
		}

	}

	public static void main(String[] args) {
		String audioFilePath = "/Users/joop/Desktop/xyz.wav";
		Play player = new Play();
		player.play(audioFilePath);
	}

}



Thanks in advance.
;JOOP!

Is This A Good Question/Topic? 0
  • +

Replies To: JAVA9 error: can not instrument ...

#2 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12148
  • View blog
  • Posts: 45,161
  • Joined: 27-December 08

Re: JAVA9 error: can not instrument ...

Posted 01 November 2017 - 04:53 AM

Moved out of the Discussion Lounge to the main Java forum. Please reserve the Discussion Lounge for topical discussion rather than programming help questions.
Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3444
  • View blog
  • Posts: 15,606
  • Joined: 20-September 08

Re: JAVA9 error: can not instrument ...

Posted 01 November 2017 - 04:58 AM

I'm guessing that's Eclipse falling over on some of its introspection facilities. It's probably something you could ignore. But if you want to fix it, i'd probably start looking into whether your version of Eclipse supports Java 9 properly

This post has been edited by g00se: 01 November 2017 - 04:58 AM
Reason for edit:: typo

Was This Post Helpful? 2
  • +
  • -

#4 Sciuriware  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 17-August 13

Re: JAVA9 error: can not instrument ...

Posted 02 November 2017 - 01:52 PM

You were right:
when I run the class file from macOS Terminal,
even on JAVA 8, there's no message at all
and the program seems to work fine.
Thanks.
;JOOP!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1