Unexpected token issue in Java - 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

Related

What is the difference between java.lang.NoSuchMethodError main Exception in thread "main " and Error: Main method not found in class

I have this class
public class demo3 {
private static void sum()
{
}
}
when I tried to run this class, I expected the error to be java.lang.NoSuchMethodError main Exception in thread "main "
however, the output was a bit different and I got below message
Error: Main method not found in class demo3, please define the main method as:
public static void main(String[] args)
now this got my curiosity as to in which case I will get java.lang.NoSuchMethodError or in which case I will get the other error message.
You get the Main method not found message when public static void main(String[]) can't be found in the class that you've asked the JVM to start running. That is, the entry point of the overall program cannot be found.
You get the java.lang.NoSuchMethodError message if your (already running) code attempts to invoke a method on a class which was available at compile time, but not available in the version of the class you are using at runtime (for example, you compile against one version of the library, and then update the library jar without recompiling). This can occur at any point in the program.
There doesn't look to be anything in JLS which says that NoSuchMethodError can't be thrown, rather than the Main method not found; however, failing to write a main method (either entirely, or writing one with the wrong signature) is a far more common mistake than the "class changed after compilation" case, especially for beginners, for whom the NoSuchMethodError might be too cryptic. There is no harm in providing a more user-friendly message in this one case.

java.lang.NoSuchMethodError , build process is broken

I've a problem with my build and it caused a huge headache for me.
I had an old class and I was using it to fetch data from it, and I created a new class with the same methods. When I test it locally on my machine, everything works fine, but when I try to do a build, it broke because it's unstable and I got this error in the log file:
Caused by: java.lang.NoSuchMethodError: com.mashvisor.bean.Neighborhood.getTraditionalRates()Lcom/mashvisor/database/dao/views/NeighborhoodRentalRates;
at com.mashvisor.database.dao.PropertyDao.retrieve(PropertyDao.java:91)
The NeighborhoodRentalRates class is the old class, and in my code I'm sure im not using it nor trying to access it in that line, here's my code for that line:
Hibernate.initialize(property.getNeighborhood().getTraditionalRates());
and here's it's declaration
public TraditionalNeighborhoodRentalRates getTraditionalRates() {
return traditionalRates;
}
The TraditionalNeighborhoodRentalRates is the new class, and the only change here is the class name.
Could any body help?
Your code is still calling the old method, i.e. it is looking for a method with the signature:
public NeighborhoodRentalRates getTraditionalRates() { ... }
Just using the same names it not enough. To have classes with the same (method-)interface, you have to have the same names, return types and argument types in all methods.
So you need to go through your calling code and make sure the new type is expected everywhere as return type and recompile the calling code.

"Using unpublished class" Eclipse warning

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
}

Java + Libgdx: Gdx.app.log() null pointer error

I am learning the LibGDX engine in parallel to re-learning java, and have written a simple logging class that has one method with a string argument to be passed to the Gdx.app.log(). while this isn't needed I did so to practice importing and using custom methods and classes, as well as reducing the length of the line needed to send a message to the console. the method looks like so:
import com.badlogic.gdx.Gdx;
public class logging {
public static final String tag="Console";
//contains method for logging to the console during testing.
public void log(String message){
Gdx.app.log(tag, message);
}
}
Then in the class I am using it in, it is imported properly, and a public logging 'con' is created. Up to this point everything seems to work fine because when I type con. in eclipse I get the log(message) as an autocomplete option, however when it is actually called for instance in a screen, under the show() method. when the program tries to step through that point i get a java.lang.NullPointerException which is confusing the hell out of me since everything is written properly. as an example of its use:
con.log("this is a test");
is the exact usage I attempt which seems fine in eclipse before runtime. Is there some simple idea I am failing to grasp here? or a quirk to the Gdx.app.log()? Please no responses with "just use the Gdx.app.log(); where you need to write to the log" as this is not the point of the exercise for me. thank you in advance for all the help!
If you are getting a NullPointerException in this line:
con.log("this is a test");
The only thing that can be null is con. You are probably defining it, but not actually creating it.
Logging con;
and not
Logging con = new Logging();

Couldn't find a matching Java operation for WSDD operation

I hv created a web service for the following code but am getting an exception:
org.apache.axis.InternalException: java.lang.Exception: Couldn't find a matching Java operation for WSDD operation "andrQues" (0 args)" on invoking the function.
public class Ques {
public String[] AndrQues(){
String ques[] = {"name??", "age??", "grade??"};
return ques;
}
}
Does anyone know why its occuring? Also the wsdl is not getting generated.
I found the error.
Just need to change the "AndrQues" to "andrQues" and program runs fine.
There is something wrong with your method name make sure that you have spelled your method Name correct. take care about the thing that use your method first latter in small means lower case.
just u need to change "AndrQues" to "andrQues" because by Default the web-services taking name into the lower case.
this will help..
In my case, entry into the interface WSPort.java invoking WSSoapHttpBindingImpl.java was missing.
public interface <classname> extends java.rmi.Remote
{
public <methodname>(<params>) throws java.rmi.RemoteException;
}

Categories