Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: help with a error message

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation help with a error message

    hey guys im getting an error message with my code and was just wondering if you could help me out? its sayin <identifier> expected on
    HTML Code:
     private ArrayList<DirectoryTest> entries = new ArrayList<DirectoryTest>();
    that line


    HTML Code:
    public class Directory
    {
    
        private ArrayList<DirectoryTest> entries = new ArrayList<DirectoryTest>();
    
        public void add(DirectoryTest entry)
        {
          entries.add(entry);
        }


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: help with a error message

    I don't see anything wrong with that code. Have you tried a clean re-build of your project? This is sometimes the problem (especially in Eclipse). Could you post the exact compile error you are getting?

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: help with a error message

    many thanks for the reply ive have been at my program for few hours now i have made progress but not without error messages would be grateful if you could help me
    import java.util.ArrayList;
    import java.util.List;
     
    public class Directory
    {
     
        private ArrayList<String>  StringList = new ArrayList<String>();
     
        public void add(DirectoryTest entry)
        {
          entries.add(entry);
        }
     
        public ArrayList<String> getEntries()
        {
          return entries;
        }
     
        public String findNumber(String firstName, String lastName)
        {
          DirectoryTest entry = findEntry(firstName, lastName);
     
          return entry == null ? null : entry.getNumber();
        }
     
        public void updateNumber(String firstName, String lastName, String number)
        {
          DirectoryTest entry = findEntry(firstName, lastName);
     
          if (entry == null)
          {
            throw new IllegalArgumentException("The Entry is not found");
          }
     
          entry.setNumber(number);
        }
     
       private DirectoryTest findEntry(String firstName, String lastName) 
       {
     
          for (DirectoryTest entry : entries)
          {
            if (entry.getFirstName().equalsIgnoreCase(firstName)
              && entry.getLastName().equalsIgnoreCase(lastName))
            {
              return entry;
            }
          }  
    	}
    }
    C:\javalab\lab10>javac Directory.java
    Directory.java:10: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
        public void add(DirectoryTest entry)
                        ^
    Directory.java:39: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
       private DirectoryTest findEntry(String firstName, String lastName)
               ^
    Directory.java:17: incompatible types
    found   : java.lang.String
    required: java.util.ArrayList<java.lang.String>
          return entries;
                 ^
    Directory.java:22: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
          DirectoryTest entry = findEntry(firstName, lastName);
          ^
    Directory.java:29: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
          DirectoryTest entry = findEntry(firstName, lastName);
          ^
    Directory.java:42: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
          for (DirectoryTest entry : entries)
               ^
    Directory.java:42: foreach not applicable to expression type
          for (DirectoryTest entry : entries)
                                     ^
    7 errors
     
    C:\javalab\lab10>javac Directory.java
    Directory.java:9: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
        public void add(DirectoryTest entry)
                        ^
    Directory.java:38: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
       private DirectoryTest findEntry(String firstName, String lastName)
               ^
    Directory.java:11: cannot find symbol
    symbol  : variable entries
    location: class Directory
          entries.add(entry);
          ^
    Directory.java:16: cannot find symbol
    symbol  : variable entries
    location: class Directory
          return entries;
                 ^
    Directory.java:21: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
          DirectoryTest entry = findEntry(firstName, lastName);
          ^
    Directory.java:28: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
          DirectoryTest entry = findEntry(firstName, lastName);
          ^
    Directory.java:41: cannot find symbol
    symbol  : class DirectoryTest
    location: class Directory
          for (DirectoryTest entry : entries)
               ^
    Directory.java:41: cannot find symbol
    symbol  : variable entries
    location: class Directory
          for (DirectoryTest entry : entries)
                                     ^
    8 errors
    and im gettin 8 error messages

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: help with a error message

    Does your Directory class know about the class DirectoryTest? eg are they in the same package? If not you need to import the DirectoryTest class

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: help with a error message

    i havent created it yet. so do u think when ive created tht program it will sort my other program out?

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: help with a error message

    All of the "DirectoryTest" errors are because there is no DirectoryTest class. Also, in your class you declared your array to be named StringList, but in all of your methods you access entries. Choose one or the other and stick with it.

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: help with a error message

    Quote Originally Posted by JavaNoob82 View Post
    i havent created it yet. so do u think when ive created tht program it will sort my other program out?
    The compiler must know about everything, so if you haven't created the class yet there's the problem. Once you've created the class and defined its methods used in Directory those errors should disappear.

Similar Threads

  1. how to send a message to receiver with if else statement
    By humdinger in forum Loops & Control Statements
    Replies: 10
    Last Post: December 4th, 2009, 10:56 AM
  2. SOAP Message Factory response error
    By Buglish in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: November 6th, 2008, 01:42 PM