Skip to main content

java.lang.NoSuchMethodError

10 replies [Last post]
bruceaj
Offline
Joined: 2009-10-17
Points: 0

I am getting the error, java.lang.NoSuchMethodError, during program execution. My project compiles okay. I have

dbManage.setUser(CensusCommon.user);
dbManage.setURL(CensusCommon.databaseURL);

The first statement, setUser, works fine. the second one is the giving me problems. I re-booted, thinking I had some contamination. No Joy. I changed the name of the method. Again No Joy. CensusCommon.user and CensusCommon.databaseURL are both static final variables. I changed the argument, CensusCommon.databaseURL, to a pure string, "C". Again no joy.

I am using NetBeans on an MS Vista system.

Appreciate some help!

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bruceaj
Offline
Joined: 2009-10-17
Points: 0

The method that is failing looks like:

private String databaseURL; // database URL

public void setURL(String d){
databaseURL = d;
}

Hope this helps.

MackSix
Offline
Joined: 2013-03-27
Points: 0

Your post is confusing because I have no idea what you are doing if you only post 2 or 3 lines of code. I am just guessing, but from you first post, it looks like you are trying to use a private field outside the class it is declared in. That won't work.

bruceaj
Offline
Joined: 2009-10-17
Points: 0

Yah, I know it confusing but I don't know how much code I can attach to my message. (newbie!) The routine I have is about 200 lines. I have a method within a class that is found st compile time but is not found in execution time (at execution I get the "java.lang.NoSuchMethodError")

As for accessing a private variable outside a method, that is the misleading thing I posted. That private variable is accessed via a getter method.

If you get a chance, I'd really appreciate it if you could read the various responses I have posted. Perhaps that would make my problem more clear.

Anyhow, thanks vary much for the response. I appreciate any suggestions you can give me.

Bruce

dgodbey
Offline
Joined: 2006-10-27
Points: 0

A couple of comments for you.

Do you know how to read a stack trace? You might want to show us that. If you haven't switched off java debugging, you will also have the line number where the error occurs.

Second, is your routine really 200 lines long? That is huge, and suggests that your routine is unfocused, and does many things. Remember that good programming practice has that each method does ONE thing.

bruceaj
Offline
Joined: 2009-10-17
Points: 0

No, I do not know how to read a stack trace, I can post the error list I am getting at run time. I don't know if that is a "stack trace." It is quite length. I know exactly the line that the run time execution is failing on.

My "class" that contains the failing method is 200 lines long. The method is one line of code, namely a "setter."

Thanks for the response. Appreciate you taking the time. I'll get back with the error printout when I get it.

Thanks.

bruceaj
Offline
Joined: 2009-10-17
Points: 0

My apologies again. I guess there are no other replies.

I am using NetBeans for development. I am on a MS Vista system.

The class I am having problems with is in another class which is my library of common classes.

The problem I am having is that I have a method that is found by the compiler (I get a clean compile) but fails at execution with the "jave.lang.NoSuchError" message.

When I am editing and type the class instantiated object followed by "period" (class.) the method (getDatabaseURL) shows up in the drop down list of methods. So the editor is finding the method correctly.

When I debug step through the execution, other methods (mostly getters) in this problem class execute fine. When I get the problem method (another getter) I get the "java. lang.NoSuchMethodError".

One other thing i did was add a new method to my problem class. This also compiled okay but failed at execution time with the same message. So, it looks like any "new" methods I add to the class are failing. The problem class is effectively a new method as I changed it's definition from when it was working.

Thinking the compile jar as different from the execution jar, I deleted the Library link NetBeans, did a clean compile of my Library routines and relinked them. I just thought "maybe there is someplace else I should look for my jar file. Can you suggest anything about this? It would be helpful.

I also wrote another class that contains much of code of the problem class and it works fine.

I hope I clarified what my problem and sorry for the misleading statement.

Look forward to any suggestions you might have.

Thank you..

Bruce

MackSix
Offline
Joined: 2013-03-27
Points: 0

bruceaj wrote:
When I am editing and type the class instantiated object followed by "period" (class.) the method (getDatabaseURL) shows up in the drop down list of methods. So the editor is finding the method correctly.

-----
getDatabaseURL can't possibly be a method or it would be getDatabaseURL(). So I still don't know what you are doing. :)

I don't understand where the class is that calls the method that can't be found. Is it a java file in your source directory? Is it in the same package as the method it is calling? Is the method being called in a jar file and have you added it to the project under Properties>>Libraries>>Add Jar/Folder? What version of NetBeans?

bruceaj
Offline
Joined: 2009-10-17
Points: 0

??? It's working. I've been struggling for 3 or 4 days with this problem. Now, I just ran it, for one time from the command line, then went back and ran it from NedBeans, and it worked.

I might be back because I have done NOTHING different, except run the jar from the command line. Perhaps that cleaned up any residual garbage!

Thanks for all your help.

Bruce

georget
Offline
Joined: 2005-07-06
Points: 0

This error usually happens when you have "overlapping" jar files somewhere in your env.
First figure out in which class that method is from and then find which jar the class belongs to. Finally remove one of the jar files.

zeeshanaayan07
Offline
Joined: 2013-08-11
Points: 0

Thanks for sharing a great post,