import javax.annotation.ParametersAreNonnullByDefault fails, but why? - java

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' }

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:

Why poi-4.1.2 for xls dos not find dependencies even though classpath is right?

I am building a simple project using Ant (not Maven as I need the project to be build and distributed in an .msi package when it is finished), added all the dependencies according to this article (end even more poi jar files) to the classpath and still I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils
It seems that there are more dependencies that the poi-4.1.2.jar file does not contain. Can I add them by hand or will it require more dependencies after that? And where do I have to look. (org.apache.commons.*)
As said building this project with Maven is not an option.
Here are all the imports I have in my class that fails to compile:
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
And those are the jar files added to the Libraries in NetBeans
poi-4.1.2.jar
poi-excelant-4.1.2.jar
poi-ooxml-4.1.2.jar
poi-ooxml-schemas-4.1.2.jar
xmlbeans-3.1.0.jar
You can look on the website what dependency you need for general operations.
Still, for me it seems, that all the import-dependecy are correct. Maybe the dependencies are not correctly added?
Every dependency can be added per hand, even those you mentioned in your post. There are two options:
add the dependency via POM (this one I cannot tell in more detail)
in Projects Structure:
go to Modules, then Dependency. Here you can add any dependency vial MAVEN PROJECT library. In your case just write org.apache.poi in the search field, click the search button and look up the list of dependency you need. Here is a picture of the last step without the list, the screenshot did not allow it.
Also, it can even happen, that your setting in the project structure is not correct. When I did everything, the dependecies were added with the Scope of "Compile", like in the picture
I did the whole procedure in IntelliJ, but it should be quite the same in all other IDE's.

Unable to Correctly Import Dependencies

I am currently trying to make a web-scraping program with jsoup. However, everything I have imported does not seem to show up when I compile my program, and it errors out saying it can't find any objects that I reference from jsoup.
This is how I imported it:
`
import java.io.*;//for website
import java.net.URL;//retrieve url
import java.util.logging.Level;//log errors
import java.util.logging.Logger;
import java.io.*; //I/O stream
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.Jsoup;//web scraper
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.net.URL;`
And these are the types of errors I'm getting:
Images.java:25: error: cannot find symbol
for(Element el : img){// for each element, get source (src) url
Where Element from jsoup cannot be found.
This is my environment variable set up, since I thought that would have to do with it.
This issue is very weird to me, because I seem to be importing everything correctly. I also have the jsoup.jar and the extracted jsoup files in the root directory of my project, if that is the correct way to do it. I am using the java10SDK to compile through cmd, and I have have tried using intelliJ ultimate to use their dependency injection, but I can't seem to figure it out. I have also tried to compile with java7, I am not sure if it actually compiled with it with the method I tried.
Classpath image as requested:
You shoul add Maven support to your project, because it is the easiest way to manage all the dependencies. To do that you just need to select your project folder in IntelliJ from the Project Toolbar and select "Add Framework support" and then scroll down until you see "Maven".
Once you add Maven support to your project you just need to Enable Auto-imports, IntelliJ itself will display you a menu to select if you want to Enable them or not, you have to select Yes.
Finally, you need to add this block to the new file created in your project folder called pom.xml, just before the project block closes (< /project>):
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
</dependencies>
Once you do that, now you can import and use the JSOUP packages in your project. If you want to add more libraries, you can check out: https://mvnrepository.com/ and select the desired version of the library you want to install and copy&paste the dependency block on your Maven file.
As a tip, I highly recommend you to use a dependency manager (like Maven f.e.) for your projects and always add it once you create the project.
Hope it helps!

Java cannot find symbol createobjectbuilder

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

Use maven repositories in native Wicket project

we are trying to implement a web application for "Database Managment Systems" lecture.
We have used native wicket. (Not maven wicket repo, because i don't have a pom.xml file)
I want to use the Wicket Bootstrap DatePicker in the project. (http://agilecoders.de/demo/datepicker)
Can i use this datepicker extension in my project?
I downloaded the wicket bootstrap from github. (github(dot)com/l0rdn1kk0n/wicket-bootstrap/)
I found the sample file html/java codes. It imports these:
import de.agilecoders.wicket.core.markup.html.bootstrap.block.Code;
import de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapButton;
import de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.DateTextField;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.DateTextFieldConfig;
import de.agilecoders.wicket.samples.components.basecss.DatePickerModal;
import org.apache.wicket.Component;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.joda.time.DateTime;
import org.wicketstuff.annotation.mount.MountPath;
When i import the sources which start with "de.agilecoder...." Eclipse says "The import de cannot be resolved"
How can i solve this problem?
I dont want to use wicket's default datepicker, because it is hard to pick birthday from it.
I hope, i can expres myself.
Thanks.
If you don't want to use Maven in your project, there are two things you can do:
Use Maven to build the Wicket Bootstrap project: Download the project archive file (like you already did), download Maven and run mvn package in the Wicket Bootstrap project directory with a pom.xml file. This will result in bunch of "jar" files (under "subproject-name/target" directory) which you can add as dependencies to your project.
Just go to the "bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form" Direcotry, copy the "DateTextField.java" File to your project (in appropriate package "de.agilecoders.wicket.extensions.markup.html.bootstrap.form") and resolve all dependencies for this class in similar way. But this sounds like really hard work... You could also learn Maven in the same time ;)

Categories