Page 1 of 2 12 LastLast
Results 1 to 20 of 35
  1. #1
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Exclamation Help with a error message desparate

    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
    Java Code:
    private ArrayList<DirectoryTest> entries = new ArrayList<DirectoryTest>();
    that line

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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I wonder if your compiler is finding the class, DirectoryTest. It almost looks as though you have things backwards, that you should have a class Directory, and then in another class, DirectoryTest, have an ArrayList<Directory>.

  3. #3
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    hey Fubarable im not quite understanding fully this is the first time ive used arraylists

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You show us a part of your Directory class, but to better help me answer this question, please post your DirectoryTest class.

  5. #5
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    that is what i have Fubarable hope you can help dude
    Java Code:
    import java.util.ArrayList;
    import java.util.List;
    
    public class Directory
    {
       
        
        private ArrayList<DirectoryTest> entries = new ArrayList<DirectoryTest>();
    
        public void add(DirectoryTest entry)
        {
          entries.add(entry);
        }
        
        public ArrayList<DirectoryTest> 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;
            }
          }  
      
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The biggest thing that jumps out at me as a possible error is that your class above is written assuming that there is another class, DirectoryTest, but that it doesn't exist.

    Again, does it exist?

    Again, can you show me its code?

  7. #7
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    no it doesnt exist at the moment i just wanted to get this one sorted before movin on to my directorytest program was i wrong to declare it in the arraylist without it existing then? if so what could i replace it with? string or something like that?

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Well the first thing you need to know is the generic argument must exist, at least as an interface if not a class before you can use it. So if I declare an arraylist like so:
    Java Code:
    ArrayList<Foo>  fooList = new ArrayList<Foo>();
    There needs to be a class Foo that is reachable by the the compiler for this to work just as much as if I simply declared a Foo object:
    Java Code:
    Foo myFoo = new Foo();
    So my suggestion: use a class that exists as your generic parameter.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Chewart View Post
    no it doesnt exist at the moment i just wanted to get this one sorted before movin on to my directorytest program was i wrong to declare it in the arraylist without it existing then? if so what could i replace it with? string or something like that?
    Even if that DirectoryTest class doesn't exist your compiler wouldn't have issued that error message; what is the reported version of your compiler when you type "javac -version"?

    kind regards,

    Jos

  10. #10
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    so even tho i havent finished my directory class program should i produce another program called directorytest just so that my program compiles? sorry i a complete newbie to java ive only bin doing this 3 months

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Chewart View Post
    so even tho i havent finished my directory class program should i produce another program called directorytest just so that my program compiles? sorry i a complete newbie to java ive only bin doing this 3 months
    Can you answer my question? (see my reply #9).

    kind regards,

    Jos

  12. #12
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    hey JosAh im using j2sdk1.4.2_19

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    good pickup JosAh. You need to compile at 1.5 or higher. Currently you're compiling with the Java compiler set at 1.4.

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Chewart View Post
    hey JosAh im using j2sdk1.4.2_19
    That's your real problem: your compiler is too old; it can't compile generic classes. Upgrade your JDK installation.

    kind regards,

    Jos

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Fubarable View Post
    good pickup JosAh. You need to compile at 1.5 or higher. Currently you're compiling with the Java compiler set at 1.4.
    Yep, the error message itself was the giveaway: the compiler didn't even syntactically recognize the construct; otherwise it would've whined something about not being able to resolve DirectoryTest to a type; now it was just gibberish to the compiler.

    kind regards,

    Jos

  16. #16
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    ive got a laptop is ther a way on the cmd to find out what version of java i have on my laptop?

  17. #17
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Chewart View Post
    ive got a laptop is ther a way on the cmd to find out what version of java i have on my laptop?
    Most likely the version of your Java JVM is the same as the version of your compiler; to be sure type "java -version" for the JVM version and "javac -version" for the version of your compiler.

    kind regards,

    Jos

  18. #18
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    ok ive put my work onto my laop wher i have the java 5 version. im only gettin one error message now on line 40 which is
    Java Code:
      private DirectoryTest findEntry(String firstName, String lastName)
        
          for (DirectoryTest entry : entries)
          {
    and its sayin that ; is expected but i cnt see it

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Looks like you may be missing a curly brace?
    Java Code:
      private DirectoryTest findEntry(String firstName, String lastName) { // **** this curly brace here?
        
          for (DirectoryTest entry : entries)
          {

  20. #20
    Chewart is offline Member
    Join Date
    Nov 2009
    Posts
    75
    Rep Power
    0

    Default

    ive ammended it but styill getting errors another 2 =( im not giving up on this program i know with some guidence icould do this.. heres where my errors after puttin a { on the programs are ahppenin
    Java Code:
       private DirectoryTest findEntry(String firstName, String lastName)
        
          for (DirectoryTest entry : entries)
          {
            if (entry.getFirstName().equalsIgnoreCase(firstName);
              && entry.getLastName().equalsIgnoreCase(lastName));
            {
              return entry;
            }
          }  
      
    }
    Java Code:
      if (entry.getFirstName().equalsIgnoreCase(firstName);
    ) expected apparently and

    Java Code:
    && entry.getLastName().equalsIgnoreCase(lastName));
    "&&" illegal start of expression

Page 1 of 2 12 LastLast

Similar Threads

  1. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 03:46 PM
  2. Error Message in JBuilder
    By RavenNevarmore in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 07:53 AM
  3. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 12:45 AM
  4. java error message
    By baileyr in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 04:47 AM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 03:10 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
  •