Java: Error: package does not exist - java

I've looked everywhere and I seemingly tried everything. I can't get rid of this error. First, my code. The directory in my computer matches the one in the GitHub link, replacing Pset2:/ with W:/, here is all the code:
https://github.com/MichaelGordonII/JavaCS50/tree/master/pset2
In command prompt I use the following command:
W:/Mario/src:>javac -cp w:/Mario/src/output Mario.java
This gets me the error. I have tried other tags with the same results. I've even tried IntelliJ IDEA 15 Community and it always says I don't have an SDK. I've beat my head on a wall enough, I just need someone else's eyes.
EDIT: Error message:
W:/Mario/src>javac mario.java
mario.java:5: error: package w.mario.src.output does not exist
import w.mario.src.output.OuputToFile;
^
mario.java:6: error: package w.mario.src.output does not exist
import w.mario.src.output.OutputToConsole
^
mario.java:23: error: cannot find symbol
OutputType outputCommand = (desiredOutputType.equals("textfile")) ? new OuputToFile() : new OutputToConsole();
^
mario.java:23: error: cannot find symbol
OutputType outputCommand = (desiredOutputType.equals("textfile")) ? new OuputToFile() : new OutputToConsole();
^
symbol: class OutputToFile
location: class Mario
mario.java:23: error: cannot find symbol
OutputType outputCommand = (desiredOutputType.equals("textfile")) ? new OuputToFile() : new OutputToConsole();
^
symbol: class OutputToConsole
location: class Mario
5 errors

You are either missing one of these : JDK_HOME, JAVA_HOME. Look at this link

Related

Java code worked in Windows but not in Linux (Fedora or Ubuntu)

So I have this small Java project for study purposes where I am learning how to call functions from other java files and reference them with import. Everything works as inteded in Windows and I'm happy with it, but I just tried to work in the same project using Fedora and Ubuntu, and seems like the imports and package references just don't work.
I get this trying to compile main java file:
$ javac Ejercicio01.java
Ejercicio01.java:3: error: package actividad05.introduceDatos does not exist
import static actividad05.introduceDatos.Pregunta.*;
^
Ejercicio01.java:4: error: package actividad05.operaciones does not exist
import static actividad05.operaciones.Valores.*;
^
Ejercicio01.java:5: error: package actividad05.operaciones.algebraicas does not exist
import static actividad05.operaciones.algebraicas.Operaciones.*;
^
Ejercicio01.java:6: error: package actividad05.operaciones.geometricas does not exist
import static actividad05.operaciones.geometricas.Operaciones.*;
^
Ejercicio01.java:13: error: cannot find symbol
opcion = pideEntero("\nElija una opcion:"
^
symbol: method pideEntero(String)
location: class Ejercicio01
Ejercicio01.java:25: error: cannot find symbol
muestraPi();
^
symbol: method muestraPi()
location: class Ejercicio01
Ejercicio01.java:28: error: cannot find symbol
muestraValorAleatorio();
^
symbol: method muestraValorAleatorio()
location: class Ejercicio01
Ejercicio01.java:31: error: cannot find symbol
double num = pideDouble("Introduzca un valor: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:32: error: cannot find symbol
muestraSeno(num);
^
symbol: method muestraSeno(double)
location: class Ejercicio01
Ejercicio01.java:35: error: cannot find symbol
num = pideDouble("Introduzca un valor: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:36: error: cannot find symbol
muestraCoseno(num);
^
symbol: method muestraCoseno(double)
location: class Ejercicio01
Ejercicio01.java:39: error: cannot find symbol
muestraRaizCuadrada();
^
symbol: method muestraRaizCuadrada()
location: class Ejercicio01
Ejercicio01.java:42: error: cannot find symbol
double base = pideDouble("Introduzca base: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:43: error: cannot find symbol
double exp = pideDouble("Introduzca exponente: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:44: error: cannot find symbol
calculaPotencia(base, exp);
^
symbol: method calculaPotencia(double,double)
location: class Ejercicio01
15 errors
My main Java file references the other functions like this:
package actividad05.main;
import static actividad05.introduceDatos.Pregunta.*;
import static actividad05.operaciones.Valores.*;
import static actividad05.operaciones.algebraicas.Operaciones.*;
import static actividad05.operaciones.geometricas.Operaciones.*;
public class Ejercicio01 {
Meaning that Ejercicio01.java is in the folder src/actividad05/main, and the functions imported are in src/actividad05/introduceDatos/Pregunta.java etc, etc.
My first thought is that this is probably a classpath problem. Check where your source code is (.java files) and where you compile them to (.class files). Then check how you are trying to run the application, is the location of all the .class files on the classpath? In this case it has little to do with the OS difference, but with compilation and execution commands and file locations.
A problem which sometimes occurs when running compiled code on another OS is that the JDK or JRE has a different vendor or version. Are you using the Oracle or OpenJDK? Which version? If the version is different, even compilation might run into trouble because some Java features are different.
But the above output points in the direction of the first issue.
EDIT: the problem that the package is not found could mean that you don't have the .java file under the directories matching the package names, or that you are not calling the compiler on the root package (the source directory).
Check out: https://www.webucator.com/how-to/how-compile-packages-java.cfm

Compiling a single Java file

Relatively new to Java - I just one to update ONE file inside a JAR file. I've decompiled the JAR, and have access to the Java file.
I am trying to use javac, however when I am using it, it throws errors as it doesn't have references to various dependencies.
Do I need to compile everything to get rid of these? Is there a simple way to just compile the one file?
javac MessageNotificationService.java
...
MessageNotificationService.java:108: error: cannot find symbol
List<EmailNotification> pendingEmails = this.messageDao.findPendingNotification("merchant", "new_message");
^
symbol: class EmailNotification
location: class MessageNotificationService
MessageNotificationService.java:111: error: cannot find symbol
List<Long> ids = pendingEmails.stream().map(EmailNotification::getId).collect(Collectors.toList());
^
symbol: variable EmailNotification
location: class MessageNotificationService
MessageNotificationService.java:182: error: cannot find symbol
for (EmailNotification notification : pendingEmails) {
^
symbol: class EmailNotification
location: class MessageNotificationService
39 errors
Sorry if this is a basic question - all of the search results on this seem to be for self-contained files that don't have errors like this.
As far as I can tell, you just point to the old JAR file
javac -cp "./old-jar-file-1.0.0.jar" ./location-of-file/MessageNotificationService.java

How to fix javac package does not exist?

I am creating in my code a Java file, which I need to convert to a class. My file contains the following:
import com.company.tpch.TpchApplication;
import com.company.tpch.TpchApplicationBuilder;
import com.speedment.runtime.core.ApplicationBuilder;
public class java {
public void x() {
TpchApplication app = new TpchApplicationBuilder()
.withPassword("root")
.withLogging(ApplicationBuilder.LogType.STREAM)
.withLogging(ApplicationBuilder.LogType.APPLICATION_BUILDER)
.withSkipCheckDatabaseConnectivity()
.build();
}
}
When I try to compile the file with
javac -d . C:\Users\s\Desktop\demo\src\main\java\java.java
I have these errors:
import com.company.tpch.TpchApplication;
^
C:\Users\s\Desktop\demo\src\main\java\java.java:2: error: package com.company.tpch does not exist
import com.company.tpch.TpchApplicationBuilder;
^
C:\Users\s\Desktop\demo\src\main\java\java.java:3: error: package com.speedment.runtime.core does not exist
import com.speedment.runtime.core.ApplicationBuilder;
^
C:\Users\s\Desktop\demo\src\main\java\java.java:7: error: cannot find symbol
TpchApplication app = new TpchApplicationBuilder()
^
symbol: class TpchApplication
location: class java
C:\Users\s\Desktop\demo\src\main\java\java.java:11: error: package ApplicationBuilder does not exist
.withLogging(ApplicationBuilder.LogType.APPLICATION_BUILDER)
^
C:\Users\s\Desktop\demo\src\main\java\java.java:10: error: package ApplicationBuilder does not exist
.withLogging(ApplicationBuilder.LogType.STREAM)
^
symbol: class TpchApplicationBuilder
location: class java
How can I solve this?
You need to add all classes that are used to your command. Like this:
javac com/company/tpch/TpchApplication com/company/tpch/TpchApplicationBuilder java.java
Of course you have to change this according to your directory structure, since I don't know it.
Anyway I would recommend an IDE that compiles your whole project at once like IntelliJ/Eclipse and/or a dependency tool like Maven/Gradle.

java:10: error: cannot find symbol (with jEdit)

I've code on Java since three months. I started with Intellij Idea, but it's so heavy for my computers, so I've decided code using jEdit.
But many software that I've programmed it's in the way of Intellij, so I oppened my programs on jEdit.
As usual like me, I create a principal class that calls to next class into an Object like the next way:
W1 ejectuar = new W1 ;
But on jEdti prints the next error:
INDT.java:10: error: cannot find symbol
W1 ejecutar = new W1() ;
^
symbol: class W1
location: class INDT
INDT.java:10: error: cannot find symbol
W1 ejecutar = new W1() ;
^
symbol: class W1
location: class INDT
2 errors
Intellij create the class into a package, but I don't know how to link the both class to compile.
Call javac -cp . classname.java instead of javac classname.java and it should work.

Why am I unable to generate client side code in web services 'Hello world' example?

Link is: http://people.apache.org/~ruchithf/hw-axis2/.
Command line is: javac -extdirs d:\lib\ D:\stub\src\org\apache\ws\axis2\*.java -d d:\clientcode\
The Error is:
C:\Program
Files\Java\jdk1.6.0\bin>javac -extdirs
d:\lib\ D:\stub\src\org\apache
\ws\axis2\*.java -d d:\clientcode\
D:\stub\src\org\apache\ws\axis2\Client.java:3:
cannot find symbol symbol : class
EchoRequest location: class
org.apache.ws.axis2.SimpleServiceStub
import
org.apache.ws.axis2.SimpleServiceStub.EchoRequest;
^
D:\stub\src\org\apache\ws\axis2\Client.java:12:
cannot find symbol symbol : class
EchoRequest location: class
org.apache.ws.axis2.Client EchoRequest
request = new
SimpleServiceStub.EchoRequest(); ^
D:\stub\src\org\apache\ws\axis2\Client.java:12:
cannot find symbol symbol : class
EchoRequest location: class
org.apache.ws.axis2.SimpleServiceStub
EchoRequest request = new
SimpleServiceStub.EchoRequest();
^ Note:
D:\stub\src\org\apache\ws\axis2\SimpleServiceStub.java
uses unchecked or u nsafe operations.
Note: Recompile with -Xlint:unchecked
for details. 3 errors C:\Program
Files\Java\jdk1.6.0\bin>javac -extdirs
d:\lib\ D:\stub\src\org\apache
\ws\axis2\*.java -d d:\clientcode\
D:\stub\src\org\apache\ws\axis2\Client.java:3:
cannot find symbol symbol : class
EchoRequest location: class
org.apache.ws.axis2.SimpleServiceStub
import
org.apache.ws.axis2.SimpleServiceStub.EchoRequest;
^
D:\stub\src\org\apache\ws\axis2\Client.java:12:
cannot find symbol symbol : class
EchoRequest location: class
org.apache.ws.axis2.Client EchoRequest
request = new
SimpleServiceStub.EchoRequest(); ^
D:\stub\src\org\apache\ws\axis2\Client.java:12:
cannot find symbol symbol : class
EchoRequest location: class
org.apache.ws.axis2.SimpleServiceStub
EchoRequest request = new
SimpleServiceStub.EchoRequest();
^ Note:
D:\stub\src\org\apache\ws\axis2\SimpleServiceStub.java
uses unchecked or u nsafe operations.
Note: Recompile with -Xlint:unchecked
for details. 3 errors
Check if the Axis library really is in D:\stub\src\org\apache\ws\
...and try using double-backslashes: D:\\stub\\src\\org\\apache\\ws and d:\\lib
I can't re-create your problem since I'm using Linux, and I remember Windows users having backslash issues sometimes.
IIRC, the axis stub generator is old, and generates pre 1.5 (maybe even pre 1.4) java source code. Try setting the source flag, and see what happens.

Categories