OK, like many of the package compiling issues out there I have not found one like this out of the 12 hours I've spent searching..
Basically I have the normal setup :
My Directories are as follows: JavaCSVReader/FRC_API
My Source files are setup as this:
JavaCSVReader/CSVFile.java
JavaCSVReader/FRC_API/RobotConfig.java
(that is CSVFile.java is located in JavaCSVReader and same for RobotConfig.java)
CSVFile.java contains the lines:
package JavaCSVReader;
import JavaCSVReader.FRC_API.*;
...
RobotConfig.java contains the lines:
package JavaCSVReader.FRC_API;
import JavaCSVReader.CSVFile;
...
Both files compile fine without the lines above.
The error is thus: I receive
"cannot find symbol... class: CSVFile location: JavaCSVReader"
when I try to compile the RobotConfig.java.
I also receive the
"package does not exist: JavaCSVReader.FRC_API" error when compiling CSVSFile.java
my
CLASSPATH=/home/src/JavaCSVReader/:.:..
(I am using linux)
Your classpath setting is wrong. You should set it to
/home/src/
The compiler will take classpath as the "base" directory in order to find packages defined in the source.
it's a classpath issue.
How do you configure java environment variables?
You'd better check on it.
is your package JavaCSVReader.FRC_API; or JavaCSVReader ?
Related
So, i am running a java project which have many library that are available in the current working directory but VS code seems to not recognize these library and giving out error "The import ###### cannot be resolved" ex: The import org.apache.pdfbox.pdmodel.PDDocument cannot be resolved"
here is the image that might help you to know more about it
This is the package that i am working on :
Here the org/apache is the library contain the class file that are need to be imported and FileArrangement.java is the file having the import statements
Error i have been receiving
this is what VS code is been showing
i really need your help because i really don't have any idea how to correct this
I have checked other projects and they are also showing the same result although the import statements for java classes like . java.util.ArrayList doesn't show any kind of error and i have tried to clean java in VS code it also didn't work
i just need to correct this error of VS code to import the classes that i need
No error on java.util package
Putting the libraries in your current working directory does not work for Java, you need to add them to the classpath.
If you're using maven, that manages the classpath for you.
If not, you can manage it in VS Code by executing the Java: Configure Classpath command from the Command Palette (Ctrl+Shift+P).
You can add dependencies via Referenced libraries under the JAVA PROJECTS panel.
Or use java.project.referencedLibraries setting in settings.json.
For example:
"java.project.referencedLibraries": [
"library/**/*.jar",
"/home/username/lib/foo.jar"
]
Details can be found in configure-classpath and manage-dependencies.
I'm trying to write a simple ant build to compile a project.
The project is in eclipse and there it compiles successfully (with the eclipse-compiler).
But with ant (using javac) it appears an error and i don't know how to resolve it.
Structure of the used jar:
com
xxx
a <= package
b
a.class
Codeblock of my class:
Object o = com.xxx.a.b.method();
^
The exception of ant is:
error: cannot find symbol
symbol: variable b
location: class a
I think eclipse uses the package first to try to compile the code. javac seems to think that a is the class.
Is there a way to resolve the problem without changing the jar?
It looks like either package name is different or you have multiple class files of the same name. I would suggest checking the import statements and adding the specific jar file to classpath while compiling using javac or ant command.
To find the exact jar file, use ctrl+T then paste your class name in the box and it will tell you the jar file. Add that jar file to your ant classpath and build.
I didn't find anything in the Java Language Specification that this is an error, so it might be a javac bug.
Since it is a javac vs. Eclipse compiler thing, try one of the following:
Use the Eclipse compiler in the Ant script
If it is a javac bug, the bug may be fixed in a newer (update) JDK version
If your code does not directly reference class com.xxx.a, compile the code with the JAR in which the class com.xxx.a was removed
I'm having a bit of trouble with compiling a Java RMI assignment in packages with the command line interface on Windows 10 (can't use Eclipse or any other IDE). I need to compile and run two .java files - RemoteBankServer.java, and RemoteBankClient.java. Both of these files use other .java classes (Bank.java, RemoteBankImpl.java, RemoteBank.java, Account.java and subclasses of Account.java).
Previously, with all of my files in one folder, I could easily compile and run my server and client with two command line windows, with:
javac RemoteBankServer.java
java RemoteBankServer
and the same for RemoteBankClient.
Now that I've tested that my code works fine, I need to organize them into java packages, following this structure:
- package name: edu.btp400.w2017.client
class name: RemoteBankClient
- package name: edu.bt400.w2017.server
class names: RemoteBankImpl, RemoteBankServer
- package name: edu.btp400.w2017.common
class name: RemoteBank (and all other classes, like Bank, Account, etc.)
I've created those folders (edu/btp400/w2017/) and have placed the appropriate classes in each folder, but I can't get it to compile. For now, I have these two lines at the top of each .java file:
package edu.btp400.w2017.server; //or .common or .client
import edu.btp400.w2017.*;
But I'm still getting compilation errors when trying to compile RemoteBankServer.java (in the server folder), such as this (which is weird, because RemoteBankImpl is in the same folder and RemoteBankServer:
RemoteBankServer.java:40: error: cannot find symbol
RemoteBankImpl b1 = new RemoteBankImpl();
^
symbol: class RemoteBankImpl
location: class RemoteBankServer
as well as similar errors saying that Account and other classes cannot be found. I've looked at various posts on how to compile with Java packages using the command line interface, but I haven't gotten it working. Any help would be greatly appreciated. Sorry for the long post.
Edit: this is the command I used to compile above (after storing the files in various packages):
I tried this in the folder containing edu, and got 27 compilation errors:
javac -cp . edu/btp400/w2017/server/RemoteBankServer.java
and this inside the server folder, and got 15 compilation errors:
javac RemoteBankServer.java
Edit: Thanks to user EJP, I found out that I needed to include the subfolders in my import statements: instead of just import edu.btp400.w2017.*; I needed to do:
import edu.btp400.w2017.common.*;
import edu.btp400.w2017.server.*;
import edu.btp400.w2017.client.*;
import edu.btp400.w2017.*;
That doesn't import all the classes in the subpackages indicated by *. The asterisk only refers to classes.
You need to import all the packages individually.
I have just started learning java, so struggling in very basics. The problem i am facing currently is "cannot find symbol : class Ques". I have resolved this issue when i was accessing package from parent directory through CLASSPATH export. Now problem is i am trying to access sub-directory from sub-driectroy like this:
family.of.adam(has)/
father.java
WifeOne(sub-direc)/wifeone.java,ChildFromWifeOne.java
WifeTwo(sub-direc)/wifetwo.java,ChildFromWifeTwo.java
Now what i am trying to do is from wifetwo.java i am accessing wifeone.java. I have tried importing (wifeone)like this:
import family.of.adam.WifeOne.*;
import WifeOne.*;
In both cases it failed to import and same error occured which i mentioned above.
I have also tried solution provided in this Question but this effects classpath of WifeOne this is what i think because when i -cp method it starts showing errors related to wifeone.
I am using normal texteditor, compiling through terminal and using mac. Kindly brief me what mistake i am doing.
Assume src is your base folder(place you compile and run the program).
src/family/of/adam/FirstWife.java
if so you need to define the package startmetn the fist line of the FirstWife.java file.
package family.of.adam;
Then,If the second java file in the,
src/Main.java
In Main.java file you need to define the import statement for user the FirstWife.java class.
import family.of.adam.FirstWife;
I am trying to call a python method in java, similar functionality as Unresolved import org.python / working with jython and java?
However, I am using ant to compile and run my files. using import org.python.util will give me this error
package org.python.util does not exist
I can see that python.org.util exists in jython-2.5.0.jar.
So, here is the class path I have in my build.xml ant file:
classpath="${java.class.path}:./jgrapht/lib/jgrapht-jdk1.5.jar:\
./jgrapht/lib/jgraph.jar:./jgraphx/lib/jgraphx.jar:\
./jython/lib/jython-2.5.0.jar:./colt/lib/colt.jar:."
and I also I added the path to jython jar files to my class path. i.e. looks like echo $path gives me all the required paths. Is there anything missing here that I am not aware of?
Try this to make all classes in the package available:
import org.python.util.*;
Or this to include a particular class:
import org.python.util.TemplateAntTask;
EDIT: Also, looks like there is an extra slash after jython-2.5.0.jar in your classpath.