java - Why is the method in one class of a project not recognizing another class's method? -


i'm trying create java program eclipse simulates small town several people or characters , interactions.

i added class - character - has method - meet(character). however, when try call meet(character) character object in class - location - in same package , project in eclipse results in error: method meet(character) undefined type character.

the first chunk of code i'm including location class. includes add method.

the second chunk of code character class, including meet(character) , getid() methods

import java.util.arraylist; import java.util.collection; import java.util.iterator; import java.util.list; import java.util.listiterator;  public class location<character> implements list<character> {  private string name; private arraylist<character> occupants; private boolean professional; private int cost; private character owner; private int hours;  public location(character o,  boolean prof, string n, int c, int h) {     name = n;     professional = prof;     cost = c;     owner = o;     hours = h;  } //methods other add(character c) have been excluded public boolean add(character c) {     for(character a:occupants)     {         //this if statement part errors.          //error message: method meet(character) undefined type character         if(c.meet(a))         {             a.meet(c);         }     }     return occupants.add(c); } } 

second chunk of code, character class meet(character) method

import java.util.arraylist;   public class character {     private string firstname;     private string lastname;     private job j;     private static int count;     private int id;     private string gender;     private arraylist<integer> relations = new arraylist<integer>();      public character(string n, string l, string g)     {         firstname = n;         lastname = l;         gender = g;         id = count;         count = count + 1;     }      //method meet, not being recognized class location.     //both files in same package in eclipse project.      public boolean meet(character person)     {         relations.ensurecapacity(person.getid());         if(!(relations.get(person.getid()) > 0 && relations.get(person.getid()) <= 100))         {             relations.add(person.getid(), new integer(50));             if(relations.get(person.getid()).intvalue() == 50)             {                 return true;             }         }         return false;     }      public int getid()     {         return id;     } } 

any appreciated, , if need me provide more of code ask. i've looked problem mine haven't found way word returns relevant results.

the problem here:

class location<character> implements list<character>                ^--here--^ 

in case, name of generic character, generating issues in code. need rid of generic definition , use this:

class location implements list<character> 

in fact, don't need location class implement list<character>, use wrapper of list<character>:

public class location<character> {      private list<character> occupants;     //...  } 

last not least, highly recommend follow naming conventions java. is, rename class location per location , character char or npc or similar.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -