Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By gimbal2

Thread: java.lang.IllegalAccessError

  1. #1
    Lemuel is offline Member
    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    Angry java.lang.IllegalAccessError

    When I run the code below in Eclipse it works.

    Java Code:
    import javax.sound.midi.*;
    public class Mini{
    	public static void main(String[] args) {
    		
    		Mini mini = new Mini();
    		if(args.length < 2) {
    			System.out.println("Do not forget the arguments of the instrument and the note");
    		} else {
    			int instrument = Integer.parseInt(args[0]);
    			int note = Integer.parseInt(args[1]);
    			mini.play(instrument, note);
    		}
    	}
    	
    	public void play(int instrument, int note) {
    		
    		try {
    			
    			Sequencer player = MidiSystem.getSequencer();
    			player.open();
    			Sequence seq = new Sequence(Sequence.PPQ, 4);
    			Track track = seq.createTrack();
    			
    			MidiEvent event = null;
    			
    			ShortMessage first = new ShortMessage();
    			first.setMessage(192, 1, instrument, 0);
    			MidiEvent changeInstrument = new MidiEvent(first, 1);
    			track.add(changeInstrument);
    			
    			ShortMessage a = new ShortMessage();
    			a.setMessage(144, 1, note, 100);
    			MidiEvent noteOn = new MidiEvent(a, 1);
    			
    			ShortMessage b = new ShortMessage();
    			b.setMessage(128, 1, note, 100);
    			MidiEvent noteOff = new MidiEvent(b, 16);
    			track.add(noteOff);
    			player.setSequence(seq);
    			player.start();
    			
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		}
    	}
    }
    but the command line raises an error.

    Exception in thread "main" java.lang.IllegalAccessError: class com.sun.media.sou
    nd.AbstractPlayer cannot access its superclass com.sun.media.sound.AbstractMidiD
    evice
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :792)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:14
    2)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :792)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:14
    2)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at com.sun.media.sound.MixerSequencerProvider.getDevi ceInfo(MixerSequenc
    erProvider.java:28)
    at javax.sound.midi.MidiSystem.getFirstDevice(MidiSys tem.java:1349)
    at javax.sound.midi.MidiSystem.getFirstDevice(MidiSys tem.java:1406)
    at javax.sound.midi.MidiSystem.getFirstDevice(MidiSys tem.java:1373)
    at javax.sound.midi.MidiSystem.getDefaultDevice(MidiS ystem.java:1160)
    at javax.sound.midi.MidiSystem.getDefaultDeviceWrappe r(MidiSystem.java:1
    110)
    at javax.sound.midi.MidiSystem.getSequencer(MidiSyste m.java:439)
    at javax.sound.midi.MidiSystem.getSequencer(MidiSyste m.java:389)
    at MonsterTestDrive.play(MonsterTestDrive.java:27)
    at MonsterTestDrive.main(MonsterTestDrive.java:19)


    HELP
    What can this be?
    In Eclipse it works, but the command line does not work.

  2. #2
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: java.lang.IllegalAccessError

    Works fine for me... and in Eclipse and in Command Line..
    what are you doing exactly?

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,543
    Rep Power
    5

    Default Re: java.lang.IllegalAccessError

    Not certain how it worked for you. I had to add the noteOn to the track to get it to work in Eclipse. There are easier ways to play notes in Java.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #4
    Lemuel is offline Member
    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    Default Re: java.lang.IllegalAccessError

    I wanna this code to work within Eclipse and on the command line.

    When I say command line, I mean put this code in notepad and save as. Java

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,914
    Rep Power
    5

    Default Re: java.lang.IllegalAccessError

    You are compiling the source file on the command prompt, right? Otherwise running it is going to be quite impossible.

    Perhaps on the command prompt a different Java runtime is being used. What do you get when you type java -version?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Lemuel is offline Member
    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    Default Re: java.lang.IllegalAccessError

    Quote Originally Posted by gimbal2 View Post
    You are compiling the source file on the command prompt, right? Otherwise running it is going to be quite impossible.

    Perhaps on the command prompt a different Java runtime is being used. What do you get when you type java -version?
    C:\>java -version
    java version "1.7.0_25"
    Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
    Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

    Yes, I'm compiling the source file on the command prompt.

  7. #7
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: java.lang.IllegalAccessError

    IIRC, anything in the javax.* packages isn't installed by default with J2SE. You may need to download some additional jars. Eclipse has its own built-in JVM, and it may include the jars your command line JVM is missing.
    Get in the habit of using standard Java naming conventions!

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,914
    Rep Power
    5

    Default Re: java.lang.IllegalAccessError

    That would surprise me quite a lot if the internal compiler has different libraries on its default classpath. I'd rather take a look at the build path of the Eclipse project to see if sneakily there aren't any additional jars added in there.
    kjkrum likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: java.lang.IllegalAccessError

    Yeah, that's probably more likely.
    Get in the habit of using standard Java naming conventions!

  10. #10
    Lemuel is offline Member
    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    Default Re: java.lang.IllegalAccessError

    I'll check it out guys.

    Thank you.

Similar Threads

  1. Replies: 5
    Last Post: 03-17-2011, 02:26 PM
  2. Replies: 8
    Last Post: 11-04-2010, 01:46 PM
  3. Replies: 5
    Last Post: 06-02-2010, 01:05 PM
  4. Replies: 3
    Last Post: 06-01-2010, 03:01 PM
  5. Replies: 2
    Last Post: 09-18-2008, 07:30 AM

Posting Permissions

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