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.
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.
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
I'm looking at some examples of lwjgl 3. In their example code they import:
import static org.lwjgl.glfw.GLFW.*;
I've seen this crop up many times now and I thought I'd just get round to asking. The code then goes on to lines such as:
glfwDestroyWindow(window);
Where it calls the function in the GLFW class. However, in my IDE (eclipse luna) this does not work as intended, I would need to call:
GLFW.glfwDestroyWindow(window);
Which isn't really a problem, just an inconvenience. How is it that I can get eclipse to recognise that this function is within the class imported so I do not have to direct it.
The sample code in the getting started is dependent on newer features of lwjgl 3, which means that if you download the (as of 2014-12-05) stable build from the lwjgl download page, the code will not compile because classes referenced in the code are not present - the entire org.lwjgl.glfw package is missing from the stable download.
You must download one of the nightly builds in order to get the required functionality; this will most likely be resolved once the v3 of the library is fully released.
I have recently written a Selenium program in Java that works perfectly with the FireFoxDriver(). My step 2 is to be able to run this program on my Android device with Selendroid. I went on their website here and have been able to download the jar and connect to their localhost with port:4444.
However, when I try their example, Eclipse doesn't recognize the SelendroidDriver() and suggests me to go back to WebDriver().
Here is their code:
SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.10.0");
// My error appears when I create the new SelendroidDriver().
WebDriver driver = new SelendroidDriver(capa);
WebElement inputField = driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true", inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid", inputField.getText());
driver.quit();
I have also noticed that the SelendroidDriver class does not appear in my files although I downloaded the Selendroid jar file, version 0.10.0.
For those of you who are curious about how I fixed my problem, here is what I did:
I went to this site to get the selendroid-client jar file corresponding to the standalone version I had.
Downloading the standalone jar file was somehow not enough.
I was facing the same problem till I found the SelendroidDriver class here. Import this and change the package name according to your project.
SelendroidDriver.java has classes implementing interface methods, which in Java 1.6 can be annotated with #Override. However, in Java 1.5, #override could only be applied to methods overriding a superclass method.
Go to your project preferences and set the "Java compiler level" to 1.6 and also make sure you select JRE 1.6 to execute your program from Eclipse.
After adding this class, you would still see multiple dependency errors, but now in the SelendroidDriver.java file. You can import these classes now to counter these errors. Ensure that the package hierarchies are maintained correctly, in accordance with the GitHub directories and your working project.
After importing all these classes, the constant fields SWITCH_TO_CONTEXT, GET_CONTEXT_HANDLES and GET_CURRENT_CONTEXT_HANDLE were not being resolved. I used a poor workaround of changing them to some other available constant field for testing this sample.
I struggled a lot with this error and finally came to know that the paths have been changed in the latest releases. Use these paths and it shall work:
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.client.SelendroidDriver;
Tested this for versions 0.15.0 & 0.17.0
I am trying to make some changes to a legacy code of a plugin which was written using Java version 4. I am trying to extend a class from an imported package.
import org.eclipse.wst.xml.core.internal.document.XMLModelContext;
public class XMLModelContextForPma extends XMLModelContext
{
}
I'm quite new to plugin development. I couldn't figure out why the compiler shows
The type org.eclipse.wst.xml.core.internal.document.XMLModelContext is not visible error. Also, most of the codes in classes of this particular package are using .internal. packages which are giving Discouraged access warnings. I'm googled here and there and found it's because of non-standard/API classes.
But this is quite strange. I have the jar files in the build path but not sure what is wrong here.
I'm developing in Eclipse Juno, Mac OS X, Java 6
It looks like the class XMLModelContext is private or protected and in a different package.
If a class is declared as protected, you can only use it in other classes within the same package or any of it's sub packages.
Add that jar(org.eclipse.wst.xml.core.internal.document.XMLModelContext containing jar) to your project file path.
I am importing a Jar file "com.ibm.mq.jar" into my workspace(Eclipse IDE).
While importing, a screen came where I could see all the classes in the Jar file.
After I imported it into the work space, I was able to import the package and following statement didn't give any error.
import com.ibm.mq.*;
But, in code I am not able to use any of the classes which were there in the package.
Like, "MQC" is a class in the package, but in code it doesn't reflect("MQC cannot be resolved as a type" error comes if I try to use it).
This jar file actually contains Websphere MQ API classes.
Can anyone advise, what am I missing.
If you're using MQ 7, check its documentation here. There was some stuff going on about deprecation of com.ibm.mq.mqc and, depending on the version you use, that class was replaced by com.ibm.mq.constants.MQConstants. Like this one, there are other cases.
In fact com.ibm.mq only contains the exception MQException, so you won't find any classes there. I suggest you check the version you're using and dig a little deeper into the docs, as a first step.
I am using a 3rd party annotation processor for generating meta-data code (.java files) from the annotated classes in my project.
I have successfully configured the processor through Eclipse (Properties -> Java Compiler -> Annotation Processing) and the code generation works fine (code is automatically created and generated). Also, Eclipse successfully auto-completes the generated classes and their fields, without any errors. Let's say that I have a class "some.package.Foo" and that the generated meta-data class is "some.package.Foo_". By the help of auto-completion, I can get the following code in the Eclipse editor, without any errors:
import some.package.Foo_;
...
public class Test {
void test() {
Foo_.someField = null; // try to access a field from the generated class Foo_
}
}
However, as soon as I actually build the project (or just save the file since Build automatically is enabled), I get the error which tells that "some.package.Foo_" cannot be resolved.
It seems like Eclipse is generating and compiling the some.package.Foo_ at the same time, or more likely.
I found two temporary solutions (which are practically hindering the use of the annotation processor in the first place):
Before each build of that generated classes, right click on every generated file go to Properties and uncheck the "Derived" tick. After that, I do the cleanup of the project and the imports are fine - there are no more errors. However, if I do the cleanup one more time, the errors again show up, because the generation of the files causes the "Derived" tick to be checked again (automatically). So this is really annoying and time-consuming.
I also uncheck the "Derived" tick
from all those files, and this time
I uncheck the "Derived" tick from
the source folder and packages which
contain those files. Then I disable
the annotation processor, and then
do the cleanup. There are no more
import errors, even if I do another
cleanup, but there is no benefit of
using the annotation processor,
because if I was to change something
which would update the model, I need
to turn the annotation processor
back on, and repeat this tedious
procedure to turn it off, after it
has generated the new version of
those files.
Is this a bug in Eclipse? If yes, is there a better workaround or quick-fix than the two I have stated above? If not, what should I try to solve the problem?
I also tried rearranging the order of the libraries on the build path and it doesn't help.
I assume that you are generating sources in the last processor round. This is not recommended way and leads exactly to the problem that you had.
Explanation is here: http://code.google.com/p/acris/wiki/CodeGenerationPlatform_Pitfall_Rounds
So the my advise is to generate sources in regular processing rounds and final round should be used just for notification that processing is over or something like that.
Hopefully this helps you.
I have a similar problem, and the only thing I've found is that it's the imports specifically that don't work, but the references in the class itself do work. The workaround I've used is to use the FQCN in all cases where the generated class is needed (except when the generated class is in the same package, since then the import is obviously not needed).
So to use your example, I'd do:
public class Test {
void test() {
some.package.Foo_.someField = null; // try to access a field from the generated class Foo_
}
}
My only guess then is that the eclipse compiler is processing the imports before doing the annotation processing, which imho must be a bug in eclipse.
I know this question is over a year old, so I'd be interested to know if you've found any other way to fix it.
We were experiencing a similar problem and apparently just solved it, so thought of sharing it at SO, in case it helps someone.
We are using:
Eclipse Indigo (Build id: 20120216-1857)
m2e Connector for maven
openJPA for static metamodel class generation
Our problem:
Say, we have a package named com.abc.xyz and an entity class in there named OurEntity. When we build the projects (JPA, EJB, EAR etc. all together with an mvn clean at the beginning) the metamodel classes get generated. And also get appropriately packaged within the PU jar. But when we try to import the generated metamodel class com.abc.xyz.OurEntity_, Eclipse cannot resolve it. OP apparently got past this point:-). Maven build failed, saying it could not resolve that class. Not much help from google except for a few bug reports such as this one: https://bugs.eclipse.org/bugs/show_bug.cgi?id=350378
That bug report said importing the whole package as opposed to the single class helped. So, tried that, but with no benefit. It also said (and so did David Heitzman) that using the fully qualified class name worked for them. That did not work either.
The solution:
Added the PU jar to Eclipse build path for the project that needed to use the metamodel classes. All of a sudden all the red underlines went away (not a surprise). But the fear was there might be two PUs in the same ear. But maven automagically took care of that.
As this rather old question got some attention without pointing to the very probable eclipse bug the OP was specifically asking for, I'd like to complement the above answers with a pointer to the eclipse bug tracker:
Cannot resolve import for generated class IF processing annotations with parameters referencing constants
The workarounds include
doing a wildcard import of the package defining the generated classes (i.e. import some.package.*;)
using the fully qualified name of your generated class, i.e. referring to some.package.Foo in your code and not using an import
switch to a newer Eclipse. This specific eclipse bug is resolved with Eclipse version 4.4 (aka Luna).