Regarding AutoValue defined here:
https://github.com/google/auto/blob/master/value/userguide/builders.md
In IntelliJ, when I create a basic class using AutoValue,
public abstract class MyClass
{
public static Builder builder()
{
return new AutoValue_MyClass.Builder();
}
...
}
I get "Cannot resolve symbol 'AutoValue_MyClass'"?
Is there some way to fix this? A plugin perhaps?
I have Annotations enabled and an AutoValue plugin that helps generate AutoValue classes, but nothing seems to help resolve the AutoValue_* prefix
AutoValue generates source code. You can tell IJ to add that source code to your project, by simply clicking right on it in the project explorer, selecting 'directory', and marking it as source.
Related
For class with #Builder Eclipse auto complete (Ctrl+Space) builder methods:
ResponseVO.builder().
It also suggests new which can't work
ResponseVO.builder().new;
Error:
Syntax error on token(s), misplaced construct(s)
Also as creating new instance
new ResponseVO.builder();
Error:
ResponseVO.builder cannot be resolved to a type
Why new is added in suggestion to Builder class?
Checked with Eclipse 4.9.0 version and lower
EDIT
It's happening without lombok's builder, if extracting generated code using inner class Eclipse suggest new when calling MyClass.BuilderExampleBuilder.builder().
public class MyClass {
public static BuilderExampleBuilder builder() {
return new BuilderExampleBuilder();
}
public static class BuilderExampleBuilder {
BuilderExampleBuilder() { }
}
}
Opened Bug 558621 - [content assist] Eclipse suggests 'new' for qualified allocation even if no inner class exists
Proposing new after . is fundamentally correct, helping the user to create a qualified instance creation a la outerInstance.new InnerClass() (see JLS §15.9)
It seems wrong, however, that Eclipse proposes this syntax even if no applicable inner class exists.
I have written an annotation processor that generates a builder class for my classes annotated with #DataBuilder
#Target(AnnotationTarget.CLASS)
#Retention(AnnotationRetention.SOURCE)
annotation class DataBuilder
My classes annotated with this annotation are located in the com.my.package.model package and the generated builder class is also located in the same package com.my.package.model but in the generated directory of course build/generated/source/kapt/debug/com/my/package/model/MyModelBuilder.kt, I can use these generated classes fine inside of my model classes(written in Kotlin)
BUT I can NOT use the generated MyModelBuilder Kotlin class inside of a java class as a class member
package com.my.package.home;
import com.my.package.model.MyModelBuilder;
public class Home {
MyModelBuilder builder; // <=== AS recognizes the class, but I'm having an compilation issue
}
Android Studio recognizes the class, but I’m having this compilation issue
com/my/package/home/Home.java:4: error: cannot find symbol
MyModelBuilder builder;
^
symbol: class MyModelBuilder
location: class Home
it’s weird because I can use this generated builder class only inside of methods, this code compiles fine:
package com.my.package.home;
import com.my.package.model.MyModelBuilder;
public class Home {
public void hello() {
MyModelBuilder builder;
}
}
could somebody here help me to understand this behavior and how to fix this? In advance, thanks!
UPDATE
I just created this repo with the necessary code to replicate the issue
https://github.com/epool/HelloKapt
The project works fine after cloning and running, to replicate the issue please un-comment this line https://github.com/epool/HelloKapt/blob/master/app/src/main/java/com/nearsoft/hellokapt/app/MainActivity.java#L13
Note: If I convert my MainActivity.java class to Kotlin(MainActivity.kt) the issues is NOT reproducible and works fine, but I don’t want to do so due to some project limitations so far
Kotlin Issue: https://youtrack.jetbrains.net/issue/KT-24591
Looking at your Github project, I notice that you don't declare a dependency on kotlin-stdlib-jdk7 in the app module. When I build the module, compiler emits the following warnings:
warning: unknown enum constant AnnotationTarget.CLASS
reason: class file for kotlin.annotation.AnnotationTarget not found
warning: unknown enum constant AnnotationRetention.SOURCE
reason: class file for kotlin.annotation.AnnotationRetention not found
warning: unknown enum constant AnnotationTarget.CLASS
reason: class file for kotlin.annotation.AnnotationTarget not found
Since kotlin-stdlib-jdk7 is declared as implementation in the annotations module, the app module doesn't see it as a transitive dependency, that might be the reason why compilation fails. To fix it, you should probably declare the correct dependency in the app module, or at least use apiElements scope for kotlin-stdlib-jdk7 in annotations.
The fact that the IDE doesn't notify you that compilation failed might be a tools bug, but there's definitely no underlying Kotlin compiler issue.
I have an Interface class checked out from an svn project, and created an Interface_Tester class to preview the interface. However, when I try to run it in Eclipse I get the following error:
Error: Could not find or load main class Interface_Tester
Here is the code from the interface_tester class -
public class Interface_Tester {
public static void main(String[] args){
Interface test = new Interface();
}
}
I have seen a similar question asked on here but did not understand the answer. I need a step-by-step guide to the solution as I am a beginner. Thank you
UPDATE:
I tried running the Interface class itself and had the same error... All classes are being shown in the project explorer on the left so why is eclipse unable to locate any of them?
On the left side of Eclipse you have a project view. Try right-clicking your Interface_Tester from there and in a dropdown choose run. May be you you are trying to run something else
0.3 code.
#NotThreadSafe
public class VoicemailPlaybackFragment extends Fragment {
//
}
I am getting compile time error as "NotThreadSafe cannot be resolved to a type"
i.e, #NotThreadSafe not imported
can anyone help, thanks in advance.
That annotation is not in the standard Java or Android codebases yet.
Depending on how and why you are using this, you should either add some third-party JAR containing it to your classpath, or just add a copy to your codebase.
This page lists a few products that include the annotation.
I'm working on a Java project which was written by someone else. This person made a hierarchy of folders inside the 'src' folder. I've added a new java class into one of those folders and defined it as 'XmlFile.java'.
Then, I'm trying to have it extend a previously written class 'GenericFile.java' by writing
package //Same package GenericFile is in
public class XmlFile extends GenericFile
{
...
}
When I try to compile the project it gives me the error
Cannot find symbol
and refers me to the line
public class XmlFile extends GenericFile
if I take out
extends GenericFile
everything compiles great.
I also notice after adding the new file (XmlFile.java) I cannot delete it (the option in Edit->Delete is not selectable for that file, or for any files/folders created by the person from whom I got the project).
Is there some sort of permission issue here or some hidden scope issue caused by the permissions being strange or what?
Please help me
Cheers,
WhiteTiger
I admit I am not an expert enough to figure out "Cannot find symbol" from a Java compiler, but since there is no other answer, here is a sneaky idea -
If GenericFile is a working and useful abstract class, there has to be at least one other class (hopefully working) that extends it. Since you have the source code, find out one such file, copy it to XmlFile.java, edit it to change the constructor name to XmlFile and try to compile it. If it compiles, start from there. If not, you will know where the problem lies.
Just trying to help! Good luck, - M.S.