Half an hour ago I opened Eclipse to edit a Google App Engine app, previously everything was working fine, no errors, I haven't updated anything (at least not knowingly).
I had imported: com.google.appengine.repackaged.org.json.JSONObject
without error, however now I get this error:
use of com.google.appengine.repackaged may result in your app breaking without warning
It has never broken before, it came with the Google App Engine download for Eclipse, why has it suddenly started now? And how can I get rid of it? (they change I was making was very small and quick, it would be nice not to have to use a different JSON library)
com.google.appengine.repackaged.* contains internal classes that should not be used by application code.
org.json is implemented by many libraries, for example JSON-Java. Simply include one of them in your GAE project.
AppEngine 1.8.4 use
com.google.appengine.labs.repackaged.org.json.JSONObject
In case you don't want to have to figure this all out from first principles, here is a step-by-step:
Get the sources from https://github.com/douglascrockford/JSON-java (you can download the zip, use Git, etc.)
Make a directory in your project json/org/json and put the sources in there.
Use "Refresh" in Eclipse so that it sees and compiles the directory.
Change all the "import com.google.appengine.repackaged.org.json.xxx;" to "import org.json.xxx;" in your code
Unfortunately this adds a whole lot of Warnings, but they do seem to be harmless.
To get rid of Use of com.google.appengine.repackaged may result in your app breaking without warning. error simple declare your class with full package name. It solves your problem.
com.google.appengine.repackaged.com.google.gson.JsonObject jsonObject =
new com.google.appengine.repackaged.com.google.gson.JsonObject();
Changing my import to com.google.gson.Gson worked for me.
Package com.google.appengine.repackaged.com.google.gson has been deprecated on the latest appengine version. Therefore the following statements
import com.google.appengine.repackaged.com.google.gson.Gson;
import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
...
Gson gson = new GsonBuilder().create();
will you give you the following error in your appgengine logs:
java.lang.NoClassDefFoundError: com/google/appengine/repackaged/com/google/gson/JsonElement
You need to use the new Json library instead:
1) add new dependency to your gradle file:
compile 'com.google.code.gson:gson:2.8.1'
2) replace
import com.google.appengine.repackaged.com.google.gson.Gson;
import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
with
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Related
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);
I am trying to use SolrJ in Netbeans for my java application.
In the project library, I imported all the SolrJ java files :
org.apache.solr.client.solrj
But in my code, when I add :
import org.apache.solr.client.solrj;
It doesn't work and it says: package does not exist.
I have tried several methods but the package is never found.
What am I doing wrong here?
First, I don't think you can write the import that way. It should be more like this:
import org.apache.solr.client.solrj.*;
I don't know if Netbeans has an auto-import feature (have never used this IDE), but you might try to see if you can get Netbeans to auto-import something from solrj. Try SolrServer or QueryResponse.
Also, are you using Maven? Maven should make all this a little easier for you.
If that fails, I'm not sure what it could be, but here's a link to one or two people who had a problem very similar to yours: https://netbeans.org/projects/cnd/lists/users/archive/2007-12/message/86.
I have a project where we use a ant buildfile to create some .java files. Those built files need to reference to already existing other java files.
My problem is that the built file can have a code line as for example
arg = (Expr) new Ast.BinaryOP(lhs, BOp.B_MINUS, rhs);
where it will show an error "Ast.BinaryOP cannot be resolved to a type". I then can type Ast.BinaryOP again and use autocomplete to pick the BinaryOP part and the error will disappear. The same with BOp.B_MINUS.
I did import (probably way too many times) the necessary other files as far as I can tell.
I.e.
import cd.ir.Ast;
import cd.ir.Ast.*;
import cd.ir.Ast.Expr;
import cd.ir.Ast.BinaryOp;
import cd.ir.Ast.BinaryOp.BOp;
So far I tried
restarting Eclipse
'clean' the project
to just run the project anyway (doesn't work)
remove the "Ast." part which will work once again if I do it in Eclipse but not if generated that way
Google the problem, respectively search it on Stackoverflow which turned out to be hard as there are many related issues. There are no good keywords as far as I can tell.
deleted the project from Eclipse and imported it newly
I need to repeatedly run the ant build file to test the code from where the .java file is generated, thus changing all errors manually is not an option.
Thanks for any advice/help in advance. I will gladly provide more information if you tell me what could help.
Hit F5 on the project, open the file, and then try hitting Ctrl+Shift+O to automatically organize the imports.
After consulting with a friend who didn't see the issue either I finally found it. So logical in retrospect but small enough that I spend 2,5h trying to find it:
import cd.ir.Ast.BinaryOp;
vs:
new Ast.BinaryOP(....
BinaryOp vs. BinaryOP
I am relatively new to java as a disclaimer. I see all kinds of code examples where people "import net...." yet anytime that I try to import anything from this directory, I get an error that the compiler cannot resolve the import net. What have these other programmers done that allows them to use this import? I have seen other people having this problem but I have not seen a straight-forward answer to this question.
For instance:
import net.sourceforge.binge.Xbox360Controller;
When you import an external package, you need to have it in your program during runtime, which means that it either has to exist in YOUR project, or if it is being loaded by another program, then that program has to contain it. To add a library to your eclipse project: see THIS
I'm trying to use GeoGoogle for geocoding purposes from http://geo-google.sourceforge.net/
When I tried to use this line of code:
import geo.google.GeoAddressStandardizer;
GeoAddressStandardizer st = new GeoAddressStandardizer("AABBCC");
It says GeoAddressStandardizer and the import cannot be resolved, I also added the JAR to the build path already.
Has anyone met this issue before? Thanks
Solution: Get the geoGoogle-1.5.0.jar Instead inside https://www.cs.drexel.edu/~zl25/maven2/repo/geoGoogle/geoGoogle/1.5.0/
having a quick look through the geo-google source, this does exist as a constructor here.
public GeoAddressStandardizer(String apiKey)
So the problem has to lie in the way your application is using the jar. Are you deploying to a web server or something like that (although I'd expect a classNotFoundException)?
If you look at the build config in your IDE, does the jar exist? How did you add it?