Java cannot find symbol createobjectbuilder - java

I’m having difficulty compiling this code. I'm using Intellij-IDEA.
I downloaded the JSON Processing API jar. I also added the path to the JAR in the project's environment variables. This did not resolve the error.
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
…
JsonObjectBuilder builder = Json.createObjectBuilder();
The error is
Error:(104, 41) java: cannot find symbol
symbol: method createObjectBuilder()
location: class javax.json.Json

Have you added the json jar to the Module's Dependencies? If you right click on your project and select Open Module Settings you can then select your module and clicking on the Dependencies tab and then the + on the bottom you can add the json dependency. As it sounds like you are not using Maven, you'll want to select Java Library and browse to your json jar.

I got this error because I had an errant import statement.
Below did NOT work:
import io.vertx.core.json.Json;
After I removed the above import and added this one, everything was ok:
import javax.json.Json;
My reference / dependency (gradle flavored):
// https://mvnrepository.com/artifact/javax.json/javax.json-api
compile group: 'javax.json', name: 'javax.json-api', version: '1.1.4'
Reference is from:
https://mvnrepository.com/artifact/javax.json/javax.json-api/1.1.4

Related

Can't import class from jar file in IntelliJ

So I am trying to import this class from my jar file. IntelliJ recognizes access to all the folder structures but not the class.
Says: "Cannot resolve symbol 'Constants'.
Note that I have tried clicking "Add library 'premiumdue.main.jar' to classpath" and it still doesn't work.
I have no idea why it won't let me import the class.
Here is a minimal intellij project showing my issue: https://www.dropbox.com/s/xzvv2x1ca2lld26/jar_issues.zip?dl=0
For your sample Gradle project, the dependency jar has to be referenced in build.gradle file as described in this answer.
dependencies {
implementation files('../create_jar.jar')
}
Proof:

Import json-simple from Maven failed

I'm practicing Java JSON programming using JSON-Simple on this site which says:
All the jars available in maven repo is supported.
UPDATE:
So I've now added the external maven library to project.
But I still can't get it work.
I tried
import com.googlecode.json-simple.JSONObject;
but got:
error: ';' expected
import com.googlecode.json-simple.JSONObject;
^
Then I tried
import com.googlecode.json_simple.JSONObject;
but got:
error: package com.googlecode.json_simple.parser does not exist
import com.googlecode.json_simple.parser.JSONParser;
^
How to make it works?
I'm pretty sure you forgot to add external maven library to project. Check this out:
...and enter: org.apache.clerezza.ext:org.json.simple:0.4

How do I set up extJWNL in a Java project?

I am trying to determine whether a set of strings, from an English sentence, are all words from the WordNet dictionary. I put the JARs in a folder in my project in eclipse.
I've downloaded the binary release of extJWNL and put the JARs in a folder called lib.
I also added these jar files to the class path and the module path using Right Click > Build Path > Configure Build Path:
I used the following code to try to import dictionary
import net.sf.extjwnl.dictionary;
This error is shown on the import statement
The package net.sf.extjwnl.dictionary is accessible from more than one module:
<unnamed>, extjwnl
I thought that this error was showing up because it was a package, not a class/type. But adding a new class and trying to change the package doesn't show this new package, namely WORDNET_JARS, just the default package.
Why is this error being returned and what do I need to do to get rid of the error and import the wordnet packages?
Platforms
I am using Eclipse IDE, and write all this code in Java. The API I am trying to import is the WordNet API.
Edit (8/21/2019)
By removing the module path, it gives a new error:
Only a type can be imported. net.sf.extjwnl.dictionary resolves to a package
I'm surprised it was this easy:
Instead of
import net.sf.extjwnl.dictionary
I had to do
import net.sf.extjwnl.dictionary.*
to get all the types. The only other thing that had to be done had already been done where I add the JARs to the class path

import javax.annotation.ParametersAreNonnullByDefault fails, but why?

My import statements contain
import javax.annotation.ParametersAreNonnullByDefault;
But it fails, saying 'cannot find symbol...'
I'm using Netbeans 8.0.2, and my project uses Source format JDK8, Java platform 1.8.0.60
Typing 'javax.annotation.' doesn't show the ParametersAreNonnullByDefault in the autocompletion popup.
i'm trying to build sources from this project in Netbeans:
https://github.com/fge/java7-fs-more
What should i do to make the import statement work?
You may be missing JSR305 dependency. Here's an example for build.gradle:
dependencies { compileOnly 'com.google.code.findbugs:jsr305:3.0.1' }

Axiom class cannot be found

I'm trying to compile a simple SOAP client example shipped with Axis2. However the Java compiler cannot find the imports:
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
I have checked my classpath variable is up-to-date on the command line and it includes:
C:\axis2-1.6.1\lib
I have also checked the lib directory contains the required Axiom jars (it does)
axiom-api-1.2.12
axiom-dom-1.2.12
axiom-impl-1.2.12
And that these jars match the package I'm importing (they do). How can I still be getting the error:
error: package org.apache.axiom.om does not exist
?
Asix2 User Guide describes the directory structure and the use of Axis2 tools to prevent the need to set the CLASSPATH environment variable:
The bin directory includes a number of useful scripts. They include
axis2.bat (or axis2.sh), which enables you to easily execute a Java
command without having to manually add all the Axis2 jar files to the
classpath

Categories