I'm trying to work off of an existing code base, and one of the files has an import statement accessing the path game.format.noFlash.*. However the format folder only has files for the other classes; the noFlash file folder is nowhere to be found.
I know it must be there because when I begin to type in the import statement in intelliJ, one of the autofill options is the noFlash folder. Is there a way to access it, and if so how?
The auto-fill options are display packages and also class names
I suspect the noFlash is a class and not a folder and Intellij is suggestion that you can import it, for example:
Classes can be specified explicitly on import instead of using the wildcard character.
import javax.swing.JOptionPane; // Make a single class visible.
Related
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
I want to use the StdDraw package, and I've tried many different ways of importing it.
Of course I tried:
import StdDraw;
But, when I look at the documentation from Princeton here, it shows that StdDraw is part of Objects, so I try this:
import java.lang.Object.StdDraw;
However, this results in an error:
error: cannot find symbol in
import java.lang.Object.StdDraw;
I saw this question here but it does not answer this question either.
How do I import StdDraw? thank you.
if you want to use StdDraw you must have
either the sources
or the classes (best zipped up as jar)
as preferred way you use the sources (see http://introcs.cs.princeton.edu/java/15inout/). it says there "To use these libraries, download StdIn.java, StdOut.java, StdDraw.java, and StdAudio.java into the same directory as your program. "
once you did this the imports should be working.
NOTE: all four files are not in packages, so you should 'download' them into the 'standard' package. That means you have to download them to the root package of your project.
by the way: don't import import java.lang.Object.StdDraw; but do just import import StdDraw;
First of all check encoding of your IDE. It should be set to UTF-8. It is important if you are using MS Windows operating system.
Then create StdDraw.java class in the same package as the package of your program you are writing. Remove class declaration, leave only package declaration.
Then visit this page: https://introcs.cs.princeton.edu/java/stdlib/StdDraw.java .
Copy all its contents (Ctr-A, Ctrl-C) and then paste it into StdDraw.java file you created previously.
StdDraw.java has its own main method so try to run it in order to check that the library works correctly. You should see a window with four strange figures :) .
Don't touch StdDraw.java anymore. Now you can easily import StdDraw library and refer to its methods with name of the class.
Enjoy
I have two folders:
Network/
+ Network.java
Router/
+ Router.java
Is there any way in java to import Network.java into Router/ folder? Or I can only copy it directly into a folder for this to work?
You can import things from nearby folders using packages.
For instance, if you have this file structure (in which I have changed the names of the folders to lower case):
network/Network.java
router/Router.java
And you have
package network;
at the top of Network.java, and
package router;
at the top of Router.java, then you can import Network into Router.java using:
import network.Network;
This assumes that you are trying to import a public class, declared inside Network.java as:
public class Network {
...
IDE:
If you're using an IDE like Netbeans oder Eclipse, you can just drag and drop the file to the package required. After this action the IDE will perform some refactoring and that's it. For more details refer to the posting above.
I imported an external JAR to my project in Eclipse, by following these instructions:
Right click on the project > Build Path > Add external archives > Choosing the JAR file from the hard drive.
The JAR file than appears in the 'References libraries' section in my project, and works fine.
However, I never need to use the import keyword in my classes in order to use the classes from the JAR. I find this weird, I thought I'd have to use import myImportedJar or something similar for this to work.
Is it normal that I don't have to use the import keyword? Did I do something wrong?
The import statement is used to be able to refer to types and their members by their simple names. You don't need to import classes that are in the same package, unless they are nested members of other classes. This is true regardless of where the class comes from, for example, if it's in another .jar.
The import keyword works on a package level. If these packages are supplied by jars or not is not a feature of the java programming language.
import only makes a name available in unqualified form in your program. The following code fragments are identical:
java.util.List<Object> list = new java.util.ArrayList<>()
vs
import java.util.List;
import java.util.ArrayList;
List<Object> list = new ArrayList<>()
Now, importing a jar file in eclipse puts the classes from this jarfile on the classpath - the total "world" of available classes for your application.
I'm a seasoned PHP programmer with backgrounds within Powershell, JavaScript etc.
I see the benefits with Java and wish to dig deeper.
All the documentation though is too advanced for me atm.
A typical PHP structure:
index.php
classes/class_get.php
classes/class_set.php
Where in index.php you would have the lines
require_once "classes/class_get.php";
require_once "classes/class_set.php";
Now in Java...
I understand Windows files are in .JAR format. No problem here, easy to understand.
I am confused when creating this in eclipse. Is the strucutre;
Main.java
src*/defaultPackage**/myClass.java
* folder
** package
Where in the Main.java file you would declare "import myClass.java"?
Also other packages such as the following:
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;
I am getting errors, and this manifest file, I haven't heard of it in any tutorials yet?
Try this, this is the way to create a jar or runnable jar in eclipse
File -> Export-> Java ->Runnbale JAR file
Launch configuration : your Class containing the public static void main(String[] args)
Export destination : Target place
Library Handling:
Package required libraries into generated JAR
FINISH
a) There are no Windows files in Java. Java is cross platform.
b) Something with a slash delimiter is always a folder. Something with a dot is always a package. Don't confuse them, because it is confusing enough.
c) Don't use the term "defaulPackage", because there is such a term for the case, that you don't specify any package. Then the package of your class is called the default package.
Main.java
src*/defaultPackage**/myClass.java
Where in the Main.java file you would declare "import myClass.java"?
You never import something .java, because you import a class, not a source file. Often you only have third party compiled classes in a jar, and don't have the source. Well - maybe.
If your class belongs to a package, the name of the class is the whole package name. You can omit it from classes in the same package.
So we don't know whether Main and MyClass (use Upper case, if you like to communicate with others - else you're confusing us) belong to the same package.
If so: Don't import anything.
Else: Import the whole package name, which might contain multiple dots.
So for example:
import yourCompany.games.monstersahead.*;
or
import yourCompany.games.monstersahead.MyClass;
for example.
The package name will usually not contain folder names like src, bin, classes.