1

I'm just trying to do a simple program here so that i can try to include it on a game.

package practs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import sun.audio.*;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Project1{

    public static void main(String[] args){
        JFrame frame = new JFrame();
        frame.setSize(200,200);
        frame.setLocationRelativeTo(null);
        JButton button = new JButton("Click me");
        frame.add(button);
        button.addActionListener(new AL());
        frame.setVisible(true);
    }

    public static class AL implements ActionListener{
        public final void actionPerformed(ActionEvent e){
            music();
        }
    }

    public static void music(){
        AudioPlayer MGP = AudioPlayer.player;
        AudioStream BGM;
        AudioData MD;

        ContinousAudioDataStream loop = null;

        try{

            InputStream test = new FileInputStream("backgroundMusic.m4a");
            BGM = new AudioStream(test);
            AudioPlayer.player.start(BGM);
            MD = BGM.getData();
            loop = new ContinousAudioDataStream(MD);

        }catch(FileNotFoundException e){
            e.printStackTrace();
        }catch(IOException error){
            error.printStackTrace();
        }
        MGP.start(loop);
    }
}

The problem is, is that all the errors,(except ContinousAudioDataStream):

Access restriction: The type 'AudioPlayer' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/jre/lib/rt.jar')

These errors occur to

  • AudioPlayer
  • AudioStream
  • AudioData

  • This is what happens to ContinousAudioDataStream

  • ContinousAudioDataStream ContinousAudioDataStream cannot be resolved to a type

1 Answer 1

5

The error basically occurs if the used library is not part of official JDK API. You can disable these warning in the Eclipse preferences.

Goto

Windows -> Preferences -> Java -> Compiler -> Errors/Warnings Project -> Properties -> Java Compiler -> Errors/Warnings

Now goto Forbidden reference (access rules)” option under “Deprecated and restricted API

The default options is set to error, which restricts use of such APIs. You can change it to warning or ignore and then clean and build your code.

Or you can try removing the library from the build path and re-adding them to your project.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.