Results 1 to 6 of 6
  1. #1
    qoncept is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Compilation error I can't make any sense of

    I'm not new to Java, but this is a pretty stupid question and I'm pulling my hair out. I have 2 files:

    ScalingMetadata.java
    Java Code:
    package com.romraider.metadata;
    
    public class ScalingMetadata {
    	private String name;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    }
    ScalingMetadataList.java
    Java Code:
    package com.romraider.metadata;
    
    import java.util.ArrayList;
    import com.romraider.metadata.exception.ScalingNotFoundException;
    
    public class ScalingMetadataList<ScalingMetadata> extends ArrayList<ScalingMetadata> {
    
    	public ScalingMetadata get(String name) throws ScalingNotFoundException {
    		for (ScalingMetadata s : this) {
    			if (s.getName().equalsIgnoreCase(name)) return s;
    		}
    		throw new ScalingNotFoundException();
    	}
    }
    And the compliation error:
    The method getName() is undefined for the type ScalingMetadata

    Both files are saved, how can I possibly get an error?!

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    11

    Default

    It sounds like you might have an old class file for ScalingMetadata in your path.

  3. #3
    stackptr89 is offline Member
    Join Date
    Nov 2010
    Posts
    13
    Rep Power
    0

    Default

    I'm not too sure. but I think you need a constructor for your String variable

  4. #4
    qoncept is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    I think you're right, toadaly, but I can't figure out how to fix it. I've deleted the project and re-imported from SVN, deleted my entire workspace and reimported (in Eclipse), and no matter what I do my ScalingMetadata class won't work correctly. Do you have any ideas?

    Thanks for the help!

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default

    Quote Originally Posted by qoncept View Post
    I'm not new to Java, but this is a pretty stupid question and I'm pulling my hair out. I have 2 files:

    ScalingMetadata.java
    Java Code:
    package com.romraider.metadata;
    
    public class ScalingMetadata {
    	private String name;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    }
    ScalingMetadataList.java
    Java Code:
    package com.romraider.metadata;
    
    import java.util.ArrayList;
    import com.romraider.metadata.exception.ScalingNotFoundException;
    
    public class ScalingMetadataList<ScalingMetadata> extends ArrayList<ScalingMetadata> {
    
    	public ScalingMetadata get(String name) throws ScalingNotFoundException {
    		for (ScalingMetadata s : this) {
    			if (s.getName().equalsIgnoreCase(name)) return s;
    		}
    		throw new ScalingNotFoundException();
    	}
    }
    And the compliation error:
    The method getName() is undefined for the type ScalingMetadata

    Both files are saved, how can I possibly get an error?!
    Remove that first <ScalingMetaData> from that list class; you're accidentally using ScalingMetaData as a generic name and that generic class doesn't (necessarily) have a getName() method.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    qoncept is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Remove that first <ScalingMetaData> from that list class; you're accidentally using ScalingMetaData as a generic name and that generic class doesn't (necessarily) have a getName() method.

    kind regards,

    Jos
    That worked, THANK YOU! That was driving me crazy.

Similar Threads

  1. Strange Compilation Error About Generics
    By dhafirnz in forum Advanced Java
    Replies: 7
    Last Post: 11-16-2010, 09:54 AM
  2. bean compilation error
    By technical_helps@yahoo.com in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-30-2009, 12:21 AM
  3. JAVA compilation error in UNIX
    By satish kumar in forum Advanced Java
    Replies: 9
    Last Post: 08-08-2008, 08:36 AM
  4. compilation error(version problem?)
    By Ms.Ranjan in forum New To Java
    Replies: 3
    Last Post: 07-11-2008, 05:31 PM
  5. compilation error with Jcreator
    By Heather in forum JCreator
    Replies: 2
    Last Post: 06-30-2007, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •