Package com.google does not exist - java

I'm using Netbeans IDE 7.0.1.
I base my question on the CalculatorApp sample application available with the IDE.
The sample is running fine but I wish I could use some JSON, ad so I download google-gson-stream-1.7.1.jar library, and included it in my libraries :
- right click on "Library", then "Properties" then "Add JAR/Folder" and selected my JAR (located somewhere in "My Documents/Download".
The problem is that when i type the following :
import com.google.gson;
(or even com.google), the IDE fires a "Package com.google does not exist". The JAR and its hierarchy is correctly shown on the left side pane,in the "Libraries" section. Most surprising, the IDE can autocomplete the com.google.** stuff.
AFAIK, I need to further to get this work, don't I ? Any ideas ?
Thank you !

In Java, import statements are for classes and interfaces (types) not for packages themselves. Are you sure you tried to import a class under com.google.gson package and not the package itself?
import com.google.gson.Foo; should work.
So should
import com.google.gson.*; or
import com.google.*;
Note however that wildcard imports aren't particularly recommended.

I am using:
import com.google.gson.Gson;

Related

Eclipse cannot import import com.google.maps.* (For java Fx programme)

I am working on a Java fx application and I need to import some libraries from com.google.maps.
I imported these libraries :
import com.google.maps.GeoApiContext;
import com.google.maps.PlaceDetailsRequest;
import com.google.maps.PlacesApi;
import com.google.maps.QueryAutocompleteRequest;
import com.google.maps.errors.ApiException;
import com.google.maps.model.AddressComponent;
import com.google.maps.model.AddressComponentType;
import com.google.maps.model.AutocompletePrediction;
import com.google.maps.model.PlaceDetails;
The java import statement is a little bit misnamed, it really means alias. import com.google.maps.GeoApiContext; really just means: Any time you find the type GeoApiContext anywhere in this source file, assume I meant to write com.google.maps.GeoApiContext.
Crucially, it does not 'invoke' any code in that class whatsoever, nor does it find or download any dependencies from the internet for you.
You will need to find the jar(s) that provide these classes and put them on the classpath of this project.
It can be as simple as downloading the relevant jar (perhaps com.google.maps-google-maps-services.jar?), put it in a lib dir someplace inside this project, finding that in the package explorer, right clicking it, and selecting 'add to classpath'.
Or, more likely, you want to use gradle or maven to take care of this for you: These tools turn simply mentioning the dependency in a list of libraries you require into automatically finding that on the internet, downloading it, configuring your IDE so that it knows where it is, and using that dependency during build and run steps.

why some imports cannot be resolved?

I'm new to java , i tried to use word net for senitment analysis .
when i used class of wordnet , i got the following failure in importing
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.lucene.analysis.en.EnglishMinimalStemmer;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileListener;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileTracker;
import org.apache.stanbol.enhancer.engines.sentiment.api.LexicalCategoryClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.api.SentimentClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.util.WordSentimentDictionary;
import org.apache.stanbol.enhancer.nlp.pos.LexicalCategory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
all the above imports cannot be resolved like org.apache.felix , org.apache.lucene ,org.apache.stanbol,org.osgi
This is because your compiler is not able to find the necessary packages and or libraries that are needed to resolve these imports. These packages must be included in your class path. For example all of the errors regarding
org.apache.felix.scr.annotations.x
can be resolved after downloading the latest .jar from https://mvnrepository.com/artifact/org.apache.felix/org.apache.felix.scr.annotations/1.11.0
Follow these steps to include jar files in your class path.
-
Drag the required jar file from your download directory to the src
directory of your project in eclipse
Right click on the jar file, Select Build Path and then select Add To Build Path option.
A dialogue box will appear asking you to link all files in the jar file, just stick with the defaults and hit OK.
You are done now, all your errors regarding imports will be resolved.
These packages need to be within the compiler's class path.
Another way to say it : the compiler needs to be able to know where to find these files. This imposes several constraints:
these files need to actually exist in your hard drive (whether added manually, or automatically by a dependency manager)
they should be organized in folders that match the parts of the package name
the folder where they are must be within the class path, which can be specified with the 'classpath' compiler option, or in your IDE's options

JavaFX won't import in BlueJ on Mac

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.

How to import my java class into another java class in Xpages java

In my Xpage, I have added to Java classes. One is "AUser" declared in Models package and one is "AUserRepository" declared in a Repository package.
When I try and import AUser into a class in my AUserRepository... the import statement I type in is not working.
import com.Discussion.utils.AUser;
Weird thing is, If I exit out of Notes and load up eclipse standalone, and make the same kind of stuff, the import works fine. Am I missing out some important factor in Xpages?
The problem definitely is the import routing.
import Models.AUser;
import Repository.AUserRepository;
Is the project build path correct? Project - Properties - Java build path. Also, have you tried cleaning the project? Project - Clean....

The import javazoom cannot be resolved

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.

Categories