Commands regarding usage of .class files of a jar file - java

I have the .jar file of jsoup.I referred to this link to clear my doubts.
But the solution given there is not working.Even after giving that command,i am getting the following error.
Here is the error.Can someone help me with this.
G:\javap>javac -cp .;jsoup.jar Jsou.java
Jsou.java:9: error: cannot find symbol
Document doc=Jsoup.connect("www.javatpoint.com").get();
^
symbol: class Document
location: class Jsou
Jsou.java:9: error: cannot access Jsoup
Document doc=Jsoup.connect("www.javatpoint.com").get();
^
bad class file: .\Jsoup.class
class file contains wrong class: org.jsoup.Jsoup
Please remove or make sure it appears in the correct subdirectory of the cla
sspath.
2 errors

Solution found by OP:
#Jonny Henly,Thanks for the help but i got it . I wasn't importing "import org.jsoup.Jsoup" ,that's why the problem was coming.Now it's fine.

Related

error: cannot find symbol BitmapTransformation/BitmapPool

I got the following error:
cannot find symbol BitmapTransformation/BitmapPool
I found this code online and wonder if there is any way to edit it to fit in androidx?
Code: https://gist.github.com/David-Hackro/839ba14f220bb513b4a2735c29a4eb0e
If you look at the imports, those classes are from some com.bumptech.glide package, which looks like this one
So add that as a dependency in your app (follow their instructions) and you should be good to go

Why i have "error cannot find symbol" when importing some java files that are present in android source?

when i try to add
import android.view.WindowManagerGlobal;
then i receive the error :
error: cannot find symbol
import android.view.WindowManagerGlobal;
^
symbol: class WindowManagerGlobal
location: package android.view
but i see in android source code that the file is present in android/view/WindowManagerGlobal.java
why i can not import it? and as i absolutely need it, how can i import it ?
You need to add it to the classpath. One option is to download the related jar from its github page.
Can you tell us more about your environment?

How to add the package into Java?

I was running a Java code online, but there is an error for the java code. The error line is:
package binary.ga;
The error information for this line is "the declared package "binary.ga" does not match the expected package". Can anybody help me fix the problem?
Normally that means that the .java file is not in the correct folder. Your folder structure should look like:
binary/
ga/
MyClass.java
You just have to replace this line with correct package, for example my project structure looks like this:
so package for Content class is net.elenx

How to import stdIn.java and stdOut,java to resolve the regarding errors

there are 4 standard input output files
StdIn.java
StdOut.java
StdRandom.java
StdArrayIO.java
and i cant find them on my system and jcreator is generating the following errors:
error: cannot find symbol
StdOut.println();
error: cannot find symbol
int N = StdIn.readInt();
error: cannot find symbol
while (!StdIn.isEmpty()) and so
what i have already done is i downloaded a stdlib.jar file and i placed in the lib folder of jdk and also i have configured my IDE with the path but its still not working.
Use import statement to those classes from jar that you use in the code. You should know the package name. IDE like eclipse do it if you hover unknown class and fix the error. See a Java tutorial how to use import statement.

"Cannot find symbol" for my own class

I do not have a %CLASSPATH% set up. As I understand, this should not be a problem because Javac will assume a classpath of the current directory.
As you can see below, javac is unable to find my Case class even though it's in the same exact directory. Any thoughts on why this is happening? This code works fine when I use Eclipse.
C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>dir /B
Case.class
Case.java
EntryPoint.java
C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>javac EntryPoint.java
EntryPoint.java:16: cannot find symbol
symbol : class Case
location: class codejam2011.Round0.D.EntryPoint
ArrayList<Case> cases = new ArrayList<Case>();
^
EntryPoint.java:16: cannot find symbol
symbol : class Case
location: class codejam2011.Round0.D.EntryPoint
ArrayList<Case> cases = new ArrayList<Case>();
^
EntryPoint.java:24: cannot find symbol
symbol : class Case
location: class codejam2011.Round0.D.EntryPoint
cases.add(new Case(new Integer(count), line));
^
3 errors
C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>
Update 1:
After trying to compile from my package root (src), I get a new error (even after deleting the Case.class file)
C:\Documents and Settings\joep\My Documents\GCJ\src>javac -cp . codejam2011/Round0/D/EntryPoint.java
codejam2011\Round0\D\EntryPoint.java:16: cannot access codejam2011.Round0.D.Case
bad class file: .\codejam2011\Round0\D\Case.java
file does not contain class codejam2011.Round0.D.Case
Please remove or make sure it appears in the correct subdirectory of the classpath.
ArrayList<Case> cases = new ArrayList<Case>();
^
1 error
C:\Documents and Settings\joep\My Documents\GCJ\src>
Update 2:
It appears to be grabbing the Case.java file from a different package.
C:\Documents and Settings\joep\My Documents\GCJ\src>javac -d ../classes codejam2011\Round0\D\*.java
.\codejam2011\Round0\D\Case.java:4: duplicate class: codejam2011.Round0.C.Case
public class Case
^
codejam2011\Round0\D\EntryPoint.java:16: cannot access codejam2011.Round0.D.Case
bad class file: .\codejam2011\Round0\D\Case.java
file does not contain class codejam2011.Round0.D.Case
Please remove or make sure it appears in the correct subdirectory of the classpath.
ArrayList<Case> cases = new ArrayList<Case>();
^
2 errors
C:\Documents and Settings\joep\My Documents\GCJ\src>
You need to compile from the package root, not from inside the package.
So, cd to the src folder and compile from there.
javac -cp . codejam2011/Round0/D/EntryPoint.java
Update: as per your new problem, you need to recompile Case.java the same way. It was apparently compiled the same wrong way (from inside the package).
If the problem is not yet solved by compiling from the package root directory (see the other answers):
make sure all the source files contain classes with names corresponding to their file name
make sure all the source files contain a package statement corresponding to their position in the source file hierarchy
delete all your .class files before compiling (this should only be necessary once, if you checked everything else).
Thus, if the file is codejam2011\Round0\D\Case.java, it should contain package codejam2011.Round0.D; as the first declaration, and then public class Case { ... }. Also, make sure there is no other source file containing this package and class declaration.
From your error message, it looks like the package statement is package codejam2011.Round0.C; instead (and you also have a class Case in the real codejam2011.Round0.C package).
You are in the wrong directory for compiling.
location: class codejam2011.Round0.D.EntryPoint
That tells me, that your package is codejam2011.Round0.D (which is against the convention (all lowercase) but beside the point ...
cd to the parent dir of codejam2011, which is src, isn't it?
javac codejam2011\Round0\D\EntryPoint.java
might do the trick.
Often you have a directory for compiled classes, like 'bin' or 'classes'. To produce the classes there, use -d (destination):
javac -d ../classes codejam2011\Round0\D\EntryPoint.java
I have similar issue, it might not apply to all cases, but what I have done is remove .gradle, build and out folder and rebuild the program again.

Categories