Results 1 to 20 of 35
- 01-23-2010, 01:51 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
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>();
XML Code:public class Directory { private ArrayList<DirectoryTest> entries = new ArrayList<DirectoryTest>(); public void add(DirectoryTest entry) { entries.add(entry); }
-
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>.
- 01-23-2010, 02:06 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
hey Fubarable im not quite understanding fully this is the first time ive used arraylists
-
You show us a part of your Directory class, but to better help me answer this question, please post your DirectoryTest class.
- 01-23-2010, 02:13 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
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; } } }
-
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?
- 01-23-2010, 02:22 PM #7
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
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?
-
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>();
Java Code:Foo myFoo = new Foo();
- 01-23-2010, 02:34 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-23-2010, 02:34 PM #10
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
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
- 01-23-2010, 02:36 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-23-2010, 02:37 PM #12
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
hey JosAh im using j2sdk1.4.2_19
-
good pickup JosAh. You need to compile at 1.5 or higher. Currently you're compiling with the Java compiler set at 1.4.
- 01-23-2010, 02:38 PM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-23-2010, 02:43 PM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-23-2010, 02:44 PM #16
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
ive got a laptop is ther a way on the cmd to find out what version of java i have on my laptop?
- 01-23-2010, 02:46 PM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-23-2010, 02:50 PM #18
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
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) {
-
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) {
- 01-23-2010, 03:05 PM #20
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
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);
Java Code:&& entry.getLastName().equalsIgnoreCase(lastName));
Similar Threads
-
Error Message????
By Cubba27 in forum New To JavaReplies: 11Last Post: 11-21-2009, 03:46 PM -
Error Message in JBuilder
By RavenNevarmore in forum New To JavaReplies: 4Last Post: 10-08-2008, 07:53 AM -
strange Error message
By little_polarbear in forum New To JavaReplies: 4Last Post: 08-26-2008, 12:45 AM -
java error message
By baileyr in forum New To JavaReplies: 2Last Post: 01-23-2008, 04:47 AM -
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 03:10 AM
Bookmarks