"Using unpublished class" Eclipse warning - java

I'm getting the following warning message from Eclipse (yellow triangle near the code):
Multiple markers at this line
- Using unpublished class
package.SomeInterface
- Using unpublished class
package.SomeClass
Couldn't find references to the error message using search engines.
Any ideas?
Edited:
The class is public. The code is compiling and executing without any issues.

Maybe you've declared as private your class, you should post your code
public class SomeInterface{
...
code
}

Related

Kotlin/KAPT Generated Kotlin class is not recognized as class member, but it does inside of methods

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.

IntelliJ Idea can not resolve same method in super class and interface

Here i'm reading spring-security-oauth2 source code and found there was a compile error in AuthorizationServerSecurityConfigurer.
below is the capture of such error:
this is errors Idea gives : Ambiguous method call: both AbstractConfiguredSecurityBuilder.getConfigurer(..) and HttpSecurityBuilder matches
But i know abstract class can implements methods both exists in its super class and interface in Java. but Idea do not know, how can i remove such error hint(having obsession about such red color).
At last, this is the hierarchy generated by Idea about class AuthorizationServerSecurityConfigurer:

Java NoSuchMethodError when Method Exists

I am referencing PlayerUtil.getMovementSpeed(player); in my Speed class, and in my PlayerUtil class, I have the method defined as:
public static double getMovementSpeed(Player player) {
//my code here
}
But whenever the getMovementSpeed method is referenced in my other classes, it throws this error:
java.lang.NoSuchMethodError: net.Swedz.util.PlayerUtil.getMovementSpeed(Lorg/bukkit/entity/Player;)D
I thought it may be that Eclipse was exporting incorrectly, but I rebooted it and tried again with no avail.
EDIT: I did try decompiling the exported jar, and the public static double getMovementSpeed(Player player) method does exist in the exported jar.
EDIT: My friend is also having a similar issue, and is using IntelliJ, so Eclipse is not the issue.
EDIT: Class definition for PlayerUtil:
package net.Swedz.util;
public class PlayerUtil implements Listener {
//getMovementSpeed is defined in here
}
Class definition for Speed:
package net.Swedz.hack.detect.move;
public class Speed implements Hack, Listener {
//my detection methods and method containing PlayerUtil.getMovementSpeed(player);
}
SOLUTION: I found on my own that I had classes conflicting between two plugins on my server. I had one jar with net.Swedz.util.PlayerUtil and another with net.Swedz.util.PlayerUtil both with different contents. I added my project name in all lower case after the net.Swedz and it seems to have fixed it!
Thanks!
This is a very simple to troubleshoot.
you have used that method and you were able to compile that class which uses this method.
so that means at compile time it reefers the class PlayerUtil which has this method.
But runtime class loader has loaded the class PlayerUtil which doesn't contain this method.
now what you have to do is just find out where that class has been loaded from (at run time)
if you can recreate the problem while it is running using eclipse/IDEA follow these steps.
(if it runs in in application server or standalone application, then start the application server or application with debug enabled.and you can do remote debug from your IDE).
put a break-point where exception was thrown (where you call this method).
start to debug , it will hit the break-point.
then evaluate this expression PlayerUtil.class.getResource("PlayerUtil.class")
4.you can find the path where the class was loaded from.
now you have two options , decompile the class and check whether that method is these (same return type, same name , same args).
or in debug , you can evaluate PlayerUtil.class.getDeclaredMethods() to find out.
So you can solve the problem by rectifying the class path entries if it was loaded from a wrong place.

Unexpected token issue in Java

I'm currently writing a method inside a service class in spring, but I'm getting unexpected token error message while compiling. I do not see any issue in the code. PFB the code.
#Service
public class HelloService{
#Autowired
HelloDao helloDao;
public Long getName(Long id) {
Person person = helloDao.findName(id);
return person.getName();
}
}
Whenever I create a new method, this error message is appearing irrespective of the class in which I'm creating.
Any idea about this?
When I copy/paste that code into my Eclipse on Windows, I see a little square at the end of the two lines inside getName().
The square turns out to be a Unicode 'LINE SEPARATOR' (U+2028).
They don't belong there. Remove them.
Eclipse actually gives a good error message:
Syntax error on token "Invalid Character", delete this token

Xcode cannot find a java class which I'm trying to extend

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.

Categories