I am unable to import the class gpdraw in java.
import gpdraw.*;
This is the import statement I used. I double and triple checked it - it's definitely correct- but it keeps throwing the exception package gpdraw does not exist. Can anyone think of why?
I use Bluej on a Macbook, if that helps.
The problem is that gpdraw is not included in Java per default. As MadProgrammer pointed out, you have to include the library in your compile/runtime classpath.
BlueJ:
The first way is via the "Preferences" dialog. Open the "Preferences" dialogue and select the "Libraries" tab. Then add the location where your classes are as a library path. Restart BlueJ - done. The selected libraries will now be available in all projects that you open.
(http://www.bluej.org/faq.html)
Command:
javac -sourcepath src -classpath path/to/gpdraw.jar
(http://ubuntuforums.org/showthread.php?t=637270)
Related
I've been trying to create my own FTP client written in Java. I wrote one ages ago in C#, so I would like to try in Java. I created a user library for apache commons and added it to my build path. The problem is that when typing the import statement it doesn't recognise it. It finds a error at org, saying "import org cannot be resolved".
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
I am using eclipse as my IDE.
Here two screenshots showing the error:
The following line is probably missing in the module-info.java file:
requires org.apache.commons.lang3;
and in the Java Build Path the Classpath contains the broken (as you can see from the red error mark) item apache-commons-lang by mistake: select it and click Remove.
Since Java 9, modules can be specified, but this requires a correct module-info.java file and the libraries must be added to the Modulepath instead of to the Classpath. Without the module-info.java file it would be easier. Therefore, perhaps the simpler solution would be to delete module-info.java file.
In addition, the *-source.jar should be as Source attachment a child of the main JAR and the *-javadoc.jar is not needed with the source (but if, then as Javadoc location child of the main JAR).
Hint: If an error or a warning is shown with a light bulb, go to the line and click Ctrl+1 and Eclipse will suggest solutions for that problem.
I've just started a new IntelliJ project. When I try and import a java class with the IntelliJ import shortcut, the import is being added to the object and not to the top of the class like it normally would.
Where in the settings can I change this?
See Preferences/Settings > Editor > Code Style > Java if this option ...
Use fully qualified class names
... is ticked then IntelliJ will always use fully qualified class names. If you disable this option then Intellij will include the import statement and refer to the class by its 'simple' name.
Here's a screenshot showing this configuration item:
If the accepted answer is not working for anyone, Try the below points too.
Check whether the class file is in correct package and resolve if there is any issues in the class file.
Click File -> Invalidate Caches/ Restart and Click Invalidate and Restart button, Once it restarted U'll be able to import properly.
I was facing this issue with my custom / generated(protobuf) java packages.
Solution (TDLR)
Whenever you face this issue, just check the package or class that getting imported doesn't have any error(red marking).
If so try to fix that.
I was having an issue with package naming and its actual location. By generated-sources -> Right Click -> Mark Directory As -> Sources Root corrected my issue.
Check whether generated-sources or folder under the generated sources need to mark us Sources Root.
My issue was with generated java files (Adding this just to help someone else with same issue)
Intellij shows red mark for Import with wildchar(import pkg1.subpkg1.*;). Like editor was unable to recognizing 'import all' under a package.
But direct import to the inner package was fine.
On top of that an resolving issue with import class add full package to the Class itself, instead of adding import statement on top the java file.
This issue didn't affect the code compilation, only in editor it was showing red mark.
I'm programming a music player in BlueJ for a school project, and I want to make use of a few classes from the JavaFX library. However, when I try to import (see import statements below), I get an error saying "javafx.scene.media does not exist". I have downloaded the latest JDK.
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
It should be noted that since it is a school project, I am obliged to use BlueJ, so switching to another IDE (in case that might be where the problem lies) is not an option.
Thanks in advance!
At present you'll need to add the JavaFX jar manually as a library - in the future this may change, but for now, go to Tools => Preferences, click on the "Libraries" tab, click "Add", then locate jfxrt.jar - it should be in your jdk directory, under jre/lib. When you're done, you'll get something like the following:
Reset your VM (Ctrl+shift+R) and then your import statements should work properly.
hi all
i use the javazoom.jl.player.Player package but it is says The import javazoom cannot be resolved. i am using eclipse and doing Android project. i clean the project still the same error is shown. please correct me.
If eclipse can't resolve a package fragment of an import statement, then it tells you (with that error), that there is no library on the classpath that contains a class from that package (or from a package whose name starts with the missing part).
An easy way for standard java/eclipse:
create a folder lib in your projects root directory (with the eclipse workbench!)
copy and paste the jar into that folder
right-click the copied jar and select "add to build path".
This should eliminate the compiler errors immediately.
(Previous part of the answer)
Taking the error message literally, it looks like you have a line of code like that:
import javazoom;
This would be wrong, because we don't import packages but classes from a package. To import all classes from the javazoom package, we'd say:
import javazoom.*;
You should download the .jar of jLayer ( http://www.javazoom.net/javalayer/sources.html )
And add into classpath in the way Andreas_D told you.
I am trying to import:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
But I am being told these do not exist?
I downloaded:
httpclient-4.0.1.jar and httpmime-4.0.1.jar
... and placed these in the same folder as my .java files that are trying to use httpclient.
Any ideas?
I still cannot get it to work... Within the folder "Libraries" I have: apache-mime4j0.6.jar commons-codec-1.3.jar commons-logging-1.1.1.jar httpclient-4.0.1.jar httpcore-4.0.1.jar httpmime-4.0.1.jar For the java file properties it has: compile classpath runtime classpath boot classpath In each of those, it seems to refer to the jars I have imported. Still getting does not exist. :-(
I have tried to do this in Eclipse too and now those files appear in "Referenced libraries" however it still doesn't work. lol
The two jars you have mentioned need to be placed in the classpath of the project in Netbeans, not in the source directory.
In my Netbeans 6.7.1 on Mac, in the Prjects tab, you cna right click on the project and select Properties. That will bring up the project properties dialog. In there, choose the libraries item from the tree on the left. From there, choose the Add Jar/Folder in the Compile view. To add the jar to your project, use the chooser to locate it and then select it.
EDIT:
I have just downloaded the HTTPClient package and I think I see the problem:
in 4.0.1, the package structure is not as you have it defined. Instead of:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
use:
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.client.params.HttpMethodParams;
In Eclipse, press Ctrl + Shift + O to organize your imports. This will look for all unknown classes on the classpath and try to import them. You can also place your cursor on a class name and press Ctrl + Shift + M to attempt to import that single class. This is sometimes helpful for class name collision (i.e. if two packages have a HttpClient class, you can click on the desired class).
If the jars are in Referenced Libraries, then they should be on your classpath. You can verify this by right clicking the project and selecting something like Build Path > Configure Build Path, then click the libraries tab.
Also, you probably have build automatically selected by default, but if you don't, you'll need to build your project. You may also want to attempt to clear the build path and re-build it. I've seen my Eclipse get out of synch a few times and this fixed it, albeit somewhat of a fluke.
If you're using Maven, this sort of thing can sometimes occur if you have an incorrect dependency scope (i.e. runtime, or test vs. compile).
For what it's worth, unless you're utilizing the entire package, there is no reason to import an entire package's contents (i.e. import package.*).
It seems that HttpClient has changed his sintaxis from 3 to 4 version... I had same problems that all of you trying to import packages until I found this example:
http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/
This is sample is Android oriented but works on any Java Application!!! Im using netbeans 6.9.1, httpclient-4.1.1.jar, commons-codec-1.4.jar and commons-logging-1.1.1.jar
Hope you can solve your problems!!!
Had the same problem and i managed to get the solution. Here it is:
1) Download the org.apache.commons.httpclient.jar.zip file from
http://www.java2s.com/Code/Jar/o/Downloadorgapachecommonshttpclientjar.htm
and save it anywhere on your computer.
2) Right click on your NetBeans project and select Properties
3) On Project Properties Categories, select Libraries
4) Click the Add JAR/Folder button
5) Now browse to the file location where you saved your downloaded org.apache....jar.zip
file and click open button.
6) Now the file has been installed, click OK and you are done.
Note that this might require you to restart your netbeans IDE.