Reputation: 2523
I'm not sure what I did, but I seem to have messed up something in my project, because it was working fine, building, compiling etc. without issues but now the build process is giving me this error:
java: unexpected type
required: variable
found: value
And what is unusual about it, is that it is calling out an argument that I am passing into a library class that I wrote and have been using for almost two years now in just about all of my projects.
It boils down to this... the method in the library has two arguments like this:
public void myMethod(double width, double height) {
this.width = width;
this.height = height;
}
and I calling the method like this:
MyClass myClass = new MyClass();
myClass.myMethod(200.0, 70.0);
When I click on the error link, it jumps straight to the first number that I'm passing into the arguments. So, since it says it wants a variable instead if I do this, I don't get the error:
double w = 200;
double h = 70;
myClass.myMethod(w,h);
These lines of code that it is throwing an error on have been in this project for months now, and have never thrown an error before. In fact, it's been compiling and running all day until suddenly it isn't.
Also, if I create a new project, using the same library, and copy and paste the exact same lines of code into the new project, it works just fine ... it's only THIS project that is suddenly getting this error, and I don't know what I did to cause it.
Does anyone have any ideas? I'm using IntelliJ ... if that matters.
Upvotes: 0
Views: 352
Reputation: 2523
I ended up "solving" the problem by creating a new project, then migrating all of my classes/resources, etc. to the new project. It now builds, compiles, and runs just fine. Still, no idea what the issue was other than some kind of corruption maybe in that project? I might hit up JetBrains to see if it's something they have seen before.
Edit:
I FINALLY found the cause of the error, and it is DEFINITELY an IntelliJ issue.
I have a class that I include in my project templates, where everything in the class is declared public static so that those resources are available to any other class in the project. There was a line in that class that somehow got messed up. This is what it looked like in damaged form:
public static final String CSS_TABLE_VIEW = Objects.requireNonNull(resource) = Objects.requireNonNull(resource.getResource("StyleSheets/TableView.css")).toExternalForm();
And this is what it is SUPPOSED to look like:
public static final String CSS_TABLE_VIEW = Objects.requireNonNull(resource.getResource("StyleSheets/TableView.css")).toExternalForm();
The error was being thrown against code that was perfectly fine in a completely different class and none of those lines of code were referencing that damaged class either.
I tried invalidating cache, and I even went so far as to completely delete everything in the project folder EXCEPT the src folder, then I created a new Project From Existing Sources pointing it to that project folder, knowing that IntelliJ would have to completely rebuild its portion of the project, and the error STILL happened in the class that was not damaged.
When I created a new project then copied the classes over, the new project had its own copy of that damaged class so I didn't copy it over, which is why creating the new project and copying the classes over to it fixed the problem.
It wasn't until I went into each class and looked at everything that I saw that damaged line in that class.
What is interesting is that after I fixed that line, and built the project, it built just fine. Then, I did Command+Z to undo the fix so that it was damaged again, but then when I built the project, the builder caught the damaged line that I had repaired then unrepaired...
So invalidating cache didn't work, nor did rebuilding the project from source files ... I had to actually fix the error one time, then the builder spotted the right problem from that moment on. I suspect if I left it damaged then did another rebuild from source, it would most likely repeat the same problem.
I've still got a case open with JetBrains so we'll see what they say about it.
Edit #2:
After some discussion with a tech at Jet Brains, I told him to close the case because I basically fixed the problem, but he was not so eager to do that, so I preserved a copy of the project that was broken to where I could just unzip a file, and create a new project from source then try to build the project which would then throw the ambiguous error in the class that had no errors.
Jet Brains asked me for a copy of the broken project which I provided and he was able to re-create the error and ended up submitting a bug report which can be seen and tracked here if anyone is interested.
Upvotes: 1
Reputation: 11120
Often, when I get strange and unexplained errors in IntelliJ IDEA, I go to File
-> Invalidate caches
-> tick all boxes -> Invalidate and restart
and then the problem is fixed.
Upvotes: 0