Cannot find class SubscriberIdAndMessage - java

I'm trying to use the SubscriberIdAndMessage from io.eventuate.tram.consumer.common, but when I try to import it, the compiler doesn't found it. However, it finds other classes from the io.eventuate.tram.consumer.common package, like MessageHandlerDecoratorChain or MessageHandlerDecorator. Do you know what might be the problem here?

Have you tried seing if the class SubscriberIdAndMessage is public?
If you put class SubscriberIdAndMessage, it is not the same as public class SubscriberIdAndMessage.
If this is not the issue, can you post a screenshot of the error?

Related

Java - could not find or load main class error

I just added some code to a project and suddenly I get these errors. The class in question does have a main method and the other class ClientLauncher in the client package exists. I checked and the classes have the correct package listed in them. Any suggestions on what I should check? Thanks.
Error: Could not find or load main class client.ClientLauncher
selection does not contain a main type
I'm not sure if this is what was going on, because I had deleted the last project and started over. But I just got a similar error and thought I'd post this in case it helps someone. In the process of doing a similar project, I forgot to include "String args[]" in the main method definition and only had"
public static void main(). This gave a similar "does not have main method". The moment I added the above and had:
public static void main(Strings args[]);
then the error went away and the code ran correctly.

Does a ClassLoader load a complete package when there is a wildcard?

How does a Java ClassLoader load imports like import java.util.*? I am asking, because I have a custom classloader which sometimes is asked to load a package instead of a class. Example:
public Class<?> loadClass(String className) throws ClassNotFoundException
{
System.out.println(className);
return parent.loadClass(className);
}
Example output:
org.test.model.User
org.test.model
org.test.model
So it seems like the whole package is requested (may be due to import org.test.model.* ?) I am not sure if the imports are causing this (and how to handle it) or if everything is fine and should be this way. Thanks in advance!
Note: This question seems to be the root of my actual problem.
EDIT
Out of the answer below I do understand that classes are loaded when referenced and the import statement is not what is important. Anyhow, why are packages (like "org.test.model" in the example above) being loaded? Or what would such a request mean?
'import' is simply syntactic sugar. When your code gets compiled to bytecode, all classes are referenced by their complete package.name
The thing here to understand is that ClassLoader don't resolve imports,they resolve classes lazily as they are referenced .They may be resolved eagerly by using Class.forName(String className).
So basically if you are using import myclasses.unusedPackage.* ,it doesn't go for resolving all the classes present in the package but will only load a Class as it is referenced.

com.liferay.portlet.ActionResponseImpl cannot be cast to com.liferay.portlet.ActionResponseImpl

I tried to cast Action response like this:
private void mappingMethod(ActionResponse response) {
ActionResponseImpl actionResponseImpl = (ActionResponseImpl)response;
...}
In debugging on "Expression Evaluation" window I can see the type of "responce" is ActionResponseImpl, and cast does not cause exception. But on runtime I have this exeption:
java.lang.ClassCastException: com.liferay.portlet.ActionResponseImpl cannot be cast to com.liferay.portlet.ActionResponseImpl
Please tell me what is the problem.
P.S.: In PortalImpl class, the copyRequestParameters method has same string, but here it's working....
It would do you good if you refrained from using classes from portal-impl.jar in your custom plugin portlet.
ActionResponseImpl is a class in the portal-impl.jar. So if you can give a use-case as to why you are planning to use this class, then we can suggest alternative.
You have ActionResponseImpl twice on the classpath - what jars from Liferay did you include in your project? As Prakash mentions, it's portal-impl.jar, which you can not have in a plugin.
What the ClassCastException wants to tell you is that your class extends one implementation of ActionResponseImpl, but the runtime environments expects it to be another implementation - they might be identical, but as they are loaded from two different sources, the classloader cannot refer one to another superclass than it extends.
I saw this issue, when I call a method using Ajax from XHTML page. I modified my method to return simple string and removed the code that tries to modify the actionResponseImpl and that resolved the issue.
This type of errors are produced by different classloaders. A class is identified by their fully qualified class name AND its Classloader. So if you embedd portal-impl in your portlet; the action is going to receive an ActionResponseImpl instance from the portal classloader and is trying to cast this one to a class of your portlet class loader .
see more: http://www.javaspecialists.eu/archive/Issue018.html

NoClassDefFoundError exception in my thread

I get this error:
Exception in thread "http-server" java.lang.NoClassDefFoundError: org/w3c/jigmonitor/ReplyServer
but I don't undestand why. Could someone explain why does this happen?
This is the class that causes the problem:
public class ReplyServer implements Serializable
{
public ReplyServer()
{
super();
}
}
It looks like the class you're defining isn't being found by something that's trying to load it. In my experience this is caused by one of three problems:
Your package declaration for the class is not correct. In this case something on the http-sever thread is expecting your class to be declared in the package org.w3c.jigmonitor.
Your source file is not located in the correct directory. In this case, your source file should be located in a directory structure like "org/w3c/jigmonitor/", providing that's the package you actually want.
The path of the compiled class for ReplyServer is not in the classpath of your JVM. You can check this by looking at the classpath used to start your JVM and seeing if the class is actually there or not. In most generic setups servlet setups there will be a "WEB-INF/classes" folder for you to go poke around in.
Good luck!
(The link David posted gives a ton of information on this type of issue and the possible causes. I would recommend tucking that away for later)

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