IntelliJ "cannot find class" on build despite added as "compile" module - java

I added some sources as a module and in the actual Java file, it shows as found without an error: public class MyClass extends SomeClass. There's no red line and "ctrl + spacebar" shows the class and its package.
But when I choose to build the project, it throws the error:
Error:(25, 31) java: cannot find symbol
symbol: class SomeClass
What could be wrong?

Related

java calling a class from another class within same package

So I was following this tutorial:
https://spring.io/guides/gs/maven/
I cloned their repositories for the software for fear of mistyping something.
The code does not work when I compile Greeter.java using javac and then use java to run HelloWorld.java file It gives me the following error:
HelloWorld.java:5: error: cannot find symbol
Greeter greeter = new Greeter();
^
symbol: class Greeter
location: class HelloWorld
HelloWorld.java:5: error: cannot find symbol
Greeter greeter = new Greeter();
^
symbol: class Greeter
location: class HelloWorld
2 errors
I tried explicitly importing Greeter into HelloWorld using
ìmport hello.Greeter
The code works fine when I run it without the package hello;statements.
Any idea why I am getting this error??
So I followed through with the tutorial and using mvn package command and the jar file generated the project works.
So is this issue with trying to compile it with java command in the command line.
Adding directory structure of the project
pom.xml src target
./src:
main
./src/main:
java
./src/main/java:
hello
./src/main/java/hello:
Greeter.java HelloWorld.java
I assume you try to compile the sources while you're in the directory src/test/java/hello. That's the wrong directory, you have to do it from directory src/test/java and pass the directory (i.e. package) to the compiler, e.g.
javac hello/*.java
Another reason might be that you haven't compiled Greeter.java, so the compiler doesn't find the class-file while compiling Hello.java. Above command should solve that.
If you have a main method in hello run
java hello/name-of-file.java
to run your main method.

Protocol Buffers source is missing files

For background, see: How to compile google-fhir proto files
There seem to be missing .java files when compiling using protoc. I do not see those files here: https://github.com/google/protobuf/tree/master/java/core/src/main/java/com/google/protobuf either. Of course, protoc generated additional files such a Patient.java that were not in the linked folder above. I just need it to compile.
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30950: error: cannot find symbol
public com.google.fhir.stu3.proto.CodeableConceptOrBuilder getJurisdictionOrBuilder(
^
symbol: class CodeableConceptOrBuilder
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30956: error: cannot find symbol
private java.util.List<com.google.fhir.stu3.proto.CodeableConcept> topic_;
^
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30964: error: cannot find symbol
public java.util.List<com.google.fhir.stu3.proto.CodeableConcept> getTopicList() {
^
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30974: error: cannot find symbol
public java.util.List<? extends com.google.fhir.stu3.proto.CodeableConceptOrBuilder>
.... ^
100 errors.
UPDATE
Running examples/protogen/generate-proto.sh returns:
FAILED: Build did NOT complete successfully
generate-descriptors.sh: line 29: ../../bazel-bin/java/ProtoGenerator: No such file or directory
It looks like bazel did not get run correctly, because ProtoGenerator is not in hazel-bin. I ran bazel build, in the root directory where there is a BUILD file. It complained about a workspace, to which I was told to create an empty WORKSPACE file. When done, there were no errors and bazel-bin was created. Are there additional parameters than bazel build. Also, I thought I saw more than one BUILD file in addition to the one in proto/stu3, but maybe I am mistaken.

How to compile and run a multi-package NetBeans project in terminal

How do I compile and run a NetBeans Project that has multiple packages that contain multiple classes in the terminal? I get:
Error: Could not find or load main class CharacterCreatorapp.class
when trying to compile some of the classes within a package I get:
$ javac Wizard.java
Wizard.java:11: error: cannot find symbol
public class Wizard extends CharacterCreator
^
symbol: class CharacterCreator
Wizard.java:31: error: method does not override or implement a
method from a supertype
#Override
^
Wizard.java:35: error: cannot find symbol
+ super.toString()
^
symbol: variable super
location: class Wizard
3 errors
and this is after CharacterCreator.java compiled successfully.

Ignore unresolved symbols when compiling java with javac

I am using Google Plugin in STS and it reports missing class. I decided to go a quick and dirty way and download the class, compile it and put it into plugin folder or jar file.
The class is here: Java2HTMLEntityReader.java
When I compile, I of course get some errors:
Java2HTMLEntityReader.java:19: error: package org.eclipse.jdt.internal.compiler.parser does not exist
import org.eclipse.jdt.internal.compiler.parser.*;
^
Java2HTMLEntityReader.java:28: error: cannot find symbol
public class Java2HTMLEntityReader extends SubstitutionTextReader {
^
symbol: class SubstitutionTextReader
Java2HTMLEntityReader.java:58: error: cannot find symbol
setSkipWhitespace(false);
^
symbol: method setSkipWhitespace(boolean)
location: class Java2HTMLEntityReader
Java2HTMLEntityReader.java:69: error: cannot find symbol
c = nextChar();
^
symbol: method nextChar()
location: class Java2HTMLEntityReader
Java2HTMLEntityReader.java:105: error: cannot find symbol
} else if (!ScannerHelper.isWhitespace((char) c)) {
^
symbol: variable ScannerHelper
location: class Java2HTMLEntityReader
Note: Java2HTMLEntityReader.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
That's because I didn't give the java compiler refference to the package. And I don't intend to! I want to compile it with those errors, I assume it will work when I put it on the correct classpath.
If you'd use the Eclipse compiler to compile that class, you could request creation of .class files despite compile errors. On the command line this is done using the option -proceedOnError. To the best of my knowledge javac does not have such an option.
Mind you, that unresolved types in API positions (super types, method signatures) may render the resulting class file useless.
I don't really see a good reason for hacking such a stub .class file for compilation. If you have the corresponding jar file available at runtime, you should really use the same jar also during compilation.
Successful compilation means there should be no errors in the source code.
If your code contains compilation errors it cannot compile and will not produce a .class file

Error: Could not find or load main class org.antlr.Tool

I am a beginner in both java and ANTLR.
I am trying to use ANTLR in Netbeans IDE.
I was trying to run a sample example and did follow all the important steps required like setting the environment variable, including jar file and modifying built.xml.
But when I try to clean and build my application I get following errors:
Error: Could not find or load main class org.antlr.Tool
Java Result: 1
Created dir: ../NetBeansProjects/AntlrTestApp/build/empty
Created dir: ../NetBeansProjects/AntlrTestApp/build/generated-sources/ap-source-output
Compiling 1 source file to ../NetBeansProjects/AntlrTestApp/build/classes
../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:24: error: cannot find symbol
grammarLexer lexer = new grammarLexer(input);
symbol: class grammarLexer
location: class AntlrTestApp
../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:24: error: cannot find symbol
grammarLexer lexer = new grammarLexer(input);
symbol: class grammarLexer
location: class AntlrTestApp
../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:26: error: cannot find symbol
grammarParser parser = new grammarParser(tokens);
symbol: class grammarParser
location: class AntlrTestApp
../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:26: error: cannot find symbol
grammarParser parser = new grammarParser(tokens);
symbol: class grammarParser
location: class AntlrTestApp
../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:29: error: cannot find symbol
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
symbol: class Main
location: class AntlrTestApp
../NetBeansProjects/AntlrTestApp/src/antlrtestapp/AntlrTestApp.java:31: error: cannot find symbol
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
symbol: class Main
location: class AntlrTestApp
6 errors
../NetBeansProjects/AntlrTestApp/nbproject/build-impl.xml:603: The following error occurred while executing this line:
../NetBeansProjects/AntlrTestApp/nbproject/build-impl.xml:244: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)
I have been trying this since last 2-3 days and searched for all possible solutions but nothing worked for me.
It looks like you're trying to automatically generate a parser from an ANTLR 3 grammar during an Ant build. The following Ant script shows an example of this that includes the following features:
Automatically downloads the necessary version of the ANTLR 3 tool when necessary, so you don't have to include the file in source control or manually set up your build machines.
Automatically locates all .g files in the specified source folders, so you don't have to edit the build every time you add a grammar.
Complete handling of up-to-date checks for maximum incremental build performance.
https://github.com/antlr/antlr4/blob/master/build.xml
I had a similar error. Using antlr-x-complete.jar distribution solved my issue.

Categories

Resources