Home > database >  Eclipse not able to see javax package
Eclipse not able to see javax package

Time:12-19

I'm currently trying to fiddle with images, specifically convert images from JPEG, WEBP, and BMP forms to PNG forms and my method uses the javax.imageio.ImageIO class. When I tried importing it, Eclipse yelled that the package that the type was not accessible. I thought that was weird and went digging through StackOverflow on my own and found multiple answers saying I should remove and re-add the JRE. This didn't work, somewhat unsurprisingly, but while looking through my build path I noticed that the JRE was missing the entire javax package. Is there a reason this could be? Is there a fix?

The exact error reads The type javax.imageio.ImageIO is not accessible and the suggested edits ask me if I want to make class ImageIO in package javax.imageio.

I am using the latest build of Eclipse. My JDK is java-16-openjdk-amd64. I am running Ubuntu 20.04. I built this app from the ground up, so I am not using Maven (unless Eclipse uses Maven by default).

I tried compiling a basic class in my command line and it worked for some reason, despite not working in Eclipse.

I would rather not revert my JDK to an older version if I don't have to.

CodePudding user response:

It turns out I was being just being an idiot. It turns out I had actually made this with a module without realizing it. All it took for me was to get rid of the module file.

CodePudding user response:

You do not call "new" on a static class To make an instance non static of it if it ever does have such a type available from one of its static methods you cast it to that type. However, with the javax.imageio.ImageIO you make other classes from its methods.

import java.awt.image.BufferedImage;
import java.io.*;
try{  // wrap in FileNotFoundException  IOException

File input = new File("/somewhere/over/the/rainbow/cementplant.jpg");
//static classes are called directly with a method
BufferedImage bfi = (BufferedImage)javax.imageio.ImageIO.read(input);
  • Related