0

Just a simple programming question.

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


public class ReadThePic {
    public static void main(String[] args){
        BufferedImage img = null;
        try {
            img = ImageIO.read(new File("strawberry.jpg"));
        } catch (IOException e) {
        }

    }
}

Error: ImageIO cannot be resolved to a type. Why?Thanks

import javax.imageio.ImageIO;

ImageIO is not accessible due to restriction on the requiered library

Jürgen K.
  • 3,427
  • 9
  • 30
  • 66

2 Answers2

3

try

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library.

or just do: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning

you could have found the solution here: Access restriction on class due to restriction on required library rt.jar?

Community
  • 1
  • 1
ju ho
  • 318
  • 1
  • 17
2

You forgot to import the class.
Add import javax.imageio.ImageIO after your other imports and it should work.

Niklas S.
  • 1,046
  • 10
  • 22
  • actually i didn't. I had the line, but i had access restriction. ImageIO is not accessible due to restriction on the requiered library. Than the path....jre1.8.0_31 – Jürgen K. Oct 22 '15 at 13:44