2

I'm working in RAD 7.5. I'm importing a package from one web project into another. I instantiate the class and try to use one of its method, but I get a build error that the method is undefined. The method is public. All other methods work except this one. The project from which I'm importing is built properly. I've tried deleting both projects, grabbing them from version control again, and rebuilding them. What on earth could possible be the problem or what else can I check in eclipse (RAD 7.5)?

Additional information:

The method being called is not static. It is public and being called from a not static, protected, method.

Code snippets

Class I'm importing:

package com.state;

public TelcoVariableTracker() {
    super();
}

public boolean isMedicalFlag() {
    return isMedicalFlag;
}

Class with the build error:

import com.state.TelcoVariableTracker;

protected method() {

TelcoVariableTracker phoneInfo = HttpSessionUtils.getTelcoVariableTracker(request);

    if (phoneInfo.isMedicalFlag() {  // Build error: The method isMedicalFlag() is undefined for the type TelcoVariableTracker
        // Do things
    }
}
Sneftel
  • 40,271
  • 12
  • 71
  • 104
roark
  • 792
  • 1
  • 12
  • 29
  • 3
    Can you provide the code snippits? It could be something subtle in either how you call the method or the like. – corsiKa Jul 26 '12 at 14:42
  • Maybe you're trying to call a static method from a non-static method? Post some code. – davidfmatheson Jul 26 '12 at 14:49
  • Perhaps the file is in a different folder (package), and that folder isn't on your classpath? – Makoto Jul 26 '12 at 14:54
  • 1
    I am certain you have the class duplicated somewhere. Probably there is an old jar lying around. Happened to me once. – Rosdi Kasim Jul 26 '12 at 15:05
  • So I see that there indeed is a duplicate class without this method in another project in my workspace, however the package name is completely different. Why would my project use that class if I'm importing a different package from a different project? – roark Jul 26 '12 at 15:22
  • 1
    @berns This eclipse plugin might be able to help you, it can show any blocked (obscured) classes. http://classpathhelper.sourceforge.net/ – Rosdi Kasim Jul 26 '12 at 15:39
  • you may also want to end your if statement with another ). – Sean Jul 26 '12 at 17:12
  • Sorry about that, the if statement is fine in the actual code, I messed that up here trying to format it. Well, I wish I can say I tried some of your plugins and it worked, but I didn't get the chance to. A couple rebuilds and the problem went away. This did help me think about what might be wrong though, so I'll mark this as the answer. – roark Jul 26 '12 at 18:15

9 Answers9

3

I had same issue, Cleaning the project did the trick :)

1

The class can be declared twice in the same package. Therefore only the first class is loaded, and the second class has your missing method.

What a mess, you hide a method from yourself :D

Grim
  • 1,938
  • 10
  • 56
  • 123
1

This Eclipse plugin Classpath Helper can show blocked classes: http://classpathhelper.sourceforge.net/

Blocked classes happen when you have identical classes in different jar.

Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
1

You have a duplicate class in your classpath. In my case, Schema.getLogicalType() gave a method undefined error but the other Schema methods were working fine and would show up in Eclipse assist. I highlighted getLogicalType and pressed F3 and linked the source. Sure enough the method existed. I found the fix when I opened the .classpath. The source was linked to a different jar file. It got linked to phoenix-4.7.0-HBase-1.1-client.jar and it had an older org.apache.avro.Schema package inside it. The phoenix.jar conflicted with my avro-1.8.1.jar. So I just removed the phoenix.jar from the classpath to fix the problem. Hope this gives you an idea on how to fix a method undefined error.

jpllosa
  • 2,066
  • 1
  • 28
  • 30
0

I had this same issue. Eclipse was picking up the same code from same two jars, even though they were declared in two separate workspaces. I was using projects - workspace and projects - workspace_new.

I removed the other workspace and did a clean project, but to no avail at first. I had multiple locations where the identical jars were. I actually had to shut my laptop down to clear out everything as closing out and restarting eclipse wouldn't fix it. After I did that however, everything resolved and the compile errors went away. Then I added the workspace back in I had removed and eclipse was able to keep things clean.

James Drinkard
  • 15,342
  • 16
  • 114
  • 137
0

I also had this issue. In my case I had written the call to the function before actually creating the function so initially the error was expected. However after the function was created the error remained. I seems eclipse cached the error in the tab and didn't recheck the error when switching between tabs. Closing and reopening the tab fixed it for me.

John C
  • 3,052
  • 3
  • 34
  • 47
0

It could be that you have the class in your source code and the class of the same name, but older and without that method, in the jar. And you see the jar class.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
0

I had the same issue. Closing and opening the tab was not enough. Had to restart eclipse.

Lulu
  • 1
0

I tried cleaning, rebuilding, closing both files and reopening them. None of that worked. Restarting Eclipse worked.