Results 1 to 5 of 5

Thread: Java Templates

  1. #1
    llee is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Java Templates

    I've defined a class that has the following body:
    class Condition {
    ...
    ArrayList<? extends Condition> subconditions;
    ...
    Condition (..., ArrayList <? extends Condition> subconditions) {
    ...
    }
    ...
    }
    I also have a function that contains the following lines:
    ...
    Condition condition = new Condition (..., new ArrayList<Condition> ());
    ...
    Condition subcondition = DatabaseParser.parseConditionElement (...)
    condition.subconditions.add (subcondition);
    ...

    I'm getting the following error when I try to compile the above source code.

    [javac] Compiling 18 source files to /home/llee/projects/android_app_projects/options/bin/classes
    [javac] /home/llee/projects/android_app_projects/options/src/org/k4health/Ace/DatabaseParser.java:82: cannot find symbol
    [javac] symbol : method add(org.k4health.Ace.Condition)
    [javac] location: class java.util.ArrayList<capture#548 of ? extends org.k4health.Ace.Condition>
    [javac] condition.subconditions.add (subcondition);
    [javac] ^
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 error

    I'm inexperienced with Java templates and do not know what this error message means. Any help would be greatly appreciated.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Java Templates

    cannot find symbol
    symbol : method add(org.k4health.Ace.Condition)
    The compiler can not find an add() method that takes a org.k4health.Ace.Condition class object as a parameter.
    Where is this method defined?

  3. #3
    llee is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java Templates

    Quote Originally Posted by Norm View Post
    The compiler can not find an add() method that takes a org.k4health.Ace.Condition class object as a parameter.
    Where is this method defined?
    The add method should belong to the ArrayList class. condition.subconditions should be an ArrayList.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Java Templates

    Can you make a small complete program that shows the errors?

  5. #5
    llee is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java Templates

    Java Code:
    package org.k4health.Ace;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    
    // Represents medical conditions.
    public class Condition implements Serializable {
      ArrayList<? extends Condition> subconditions; 
    
      Condition (ArrayList<? extends Condition> subconditions) {
        this.subconditions = subconditions;
      }
    }
    
    public class DatabaseParser {
     static Condition parseConditionElement (Element conditionElem) {
        Condition condition = new Condition (
          new ArrayList<Condition> ()
        );
        Condition subcondition = new Condition (new ArrayList<Condition> ());
        condition.subconditions.add (subcondition); // Compiler error occurs here. 
        return condition;
      }
    }
    Last edited by Norm; 02-10-2012 at 11:15 PM. Reason: added code tags

Similar Threads

  1. Using Generic Methods like Templates?
    By slider57 in forum New To Java
    Replies: 4
    Last Post: 08-04-2011, 08:16 AM
  2. Text-field templates.
    By jdipierro in forum New To Java
    Replies: 4
    Last Post: 05-14-2010, 12:48 AM
  3. HELP! - Eclipse Templates
    By protocos in forum Eclipse
    Replies: 1
    Last Post: 03-06-2009, 02:31 AM
  4. Templates JSP
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-04-2007, 07:42 AM

Posting Permissions

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