You should be able to correct those errors with making a post.
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.
You should be able to correct those errors with making a post.
Gamb1t (August 25th, 2011)
making a post? a new thread?
No, I was commenting on post #75
Gamb1t (August 25th, 2011)
I'm confused i can fixed the error how?
What error?i can fixed the error how?
Gamb1t (August 25th, 2011)
For theName name = new Name(forename, surname);
It says that it cannot find the variable forename and i assume it will be the same for the rest.
At the top the instance variable is justprivate AddressBook addressbook;
Which holdspublic AddressBook(Contact contact) { this.contact = contact; }
If i addto the addressbookui i still get the same errorprivate Contact contact;
Where is the variable forename defined?
In the addEntry method you define all the variables to hold the data from the user.
Then you read in the values.
Now you are trying to use those values to create objects.
Look at that code and see what is the name of the variable that your are trying to use.
Where is it defined. It should be defined at the method level and not inside of a some block of code surrounded by {}s.
What method are working on now? I thought you were in the addEntry method. That is where all the data is.
Gamb1t (August 25th, 2011)
Yeah sorry i was using that as a constructor for some reason.
It's know within the addEntry method and the name statement works, the address for somereason doesn't
public void addEntry() { BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in)); String forename = ""; String surname = ""; String street = ""; String city = ""; String county = ""; String country = ""; String post = ""; if(top == MAXENTRIES){ System.out.println("Address Book is full"); return; } //asks the user for the data of the address book try{ System.out.print("Forename: "); forename = keyIn.readLine(); System.out.print("Surname: "); surname = keyIn.readLine(); System.out.print("Street: "); street = keyIn.readLine(); System.out.print("City: "); city = keyIn.readLine(); System.out.print("County: "); county = keyIn.readLine(); System.out.print("Country: "); country = keyIn.readLine(); System.out.print("Postcode: "); post = keyIn.readLine(); }catch(Exception e){ System.out.println(e); System.exit(0); } Name name = new Name(forename, surname); Address address = new Address(street, city, county, country, post); }
It says cannot find symbol - constructor Address(java.lang.String, java.lang.String, ditto etc.)
Look at the definition for the Address class and see if any of its constructor takes the arguments you are trying to pass it. If not, add a constructor to the Address class that takes those 5 String values and stores them into local variables.
Gamb1t (August 25th, 2011)
In my address class i have this constructore
public Address(String street, String city, String county, String country, Postcode post) { this.street = street; this.city = city; this.county = county; this.country = country; this.post = post; }
So guess the issue is that post doesnt take String
A Postcode object is NOT a String.
You need to create a Postcode object and use that in the constructor call to make a new Address.
Gamb1t (August 25th, 2011)
How do i do that then within the constructor i already have or a new one
You don't do it in the Address class. You do it in the addEntry method. Create a Postcode object and use it when you call the Address class constructor.
Gamb1t (August 25th, 2011)
So i createdin addentry() methodName name = new Name(forename, surname); Postcode postcode = new Postcode(post); Address address = new Address(street, city, county, country, post);
Does it compile?
Have you tried executing it?
What happens?
Gamb1t (August 25th, 2011)
i tried and i have the same error message as before
When you have an error, please post the full text.
Gamb1t (August 25th, 2011)
Name name = new Name(forename, surname); Postcode postcode = new Postcode(post); Address address = new Address(street, city, county, country, post);
the last line - error message: cannot find symbol - constructor Address(java.lang.String, java.lang.String, ditto etc.)
Did you change the last argument in the list to be a Postcode object and not a String?
Gamb1t (August 25th, 2011)
In the list i presume you mean this:
String forename = ""; String surname = ""; String street = ""; String city = ""; String county = ""; String country = ""; Postcode post = ""; if(top == MAXENTRIES){ System.out.println("Address Book is full"); return; } //asks the user for the data of the address book try{ System.out.print("Forename: "); forename = keyIn.readLine(); System.out.print("Surname: "); surname = keyIn.readLine(); System.out.print("Street: "); street = keyIn.readLine(); System.out.print("City: "); city = keyIn.readLine(); System.out.print("County: "); county = keyIn.readLine(); System.out.print("Country: "); country = keyIn.readLine(); System.out.print("Postcode: "); post = keyIn.readLine(); }catch(Exception e){ System.out.println(e); System.exit(0); } Name name = new Name(forename, surname); Postcode postcode = new Postcode(post); Address address = new Address(street, city, county, country);
Another error message onfound java.lang.String but expected PostcodePostcode post = "";
Last edited by Gamb1t; August 25th, 2011 at 03:00 AM.
"" is a String, not a Postcode object. You can Use null to initialize the variable when you define it.Postcode post = "";
However you use the variable post to read in a String from the user, so post should be defined as a String not as a Postcode as you did in post#83.
Gamb1t (August 25th, 2011)
What and where are you talking about? You need to be specific and show the code.I thought you were referring to that part to change it from a String to a Postcode object
The constructor takes a Postcode object.
You read data from a user into a String object.
Last edited by Norm; August 25th, 2011 at 08:47 AM.
Gamb1t (August 25th, 2011)
This is all of my textUI at the moment i don't have a constructor
public class AddressTextUi { //index of the last entry private int top = 0; //constant number that indicates the maximum //number of entries in the address book private static final int MAXENTRIES = 10; // private Contact[] list; private AddressBook addressbook; private Contact contact; public void mainMenu() { displayMainMenu(); } /** *The main method - DISPLAYS OPTIONS, TAKES THE OPTION AND CHECKS APPROPRIATE ACTION */ private void displayMainMenu(){ BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in)); AddressTextUi addressBook = new AddressTextUi(); String act = ""; while(true) { //displays the options System.out.println("\n[A] ADD ENTRY"); System.out.println("[D] DELETE ENTRY"); System.out.println("[U] UPDATE ENTRY"); System.out.println("[V] VIEW ALL ENTRIES"); System.out.println("[S] SEARCH ENTRIES BY SURNAME"); System.out.println("[Q] Quit"); System.out.println("Enter desired action: "); try{ //gets the choice act = keyIn.readLine(); }catch(Exception e){ System.out.println("Error"); } //checks for the appropriate action if(act.equals("A")||act.equals("a")) addressBook.addEntry(); else if(act.equals("Q")||act.equals("q")) {System.out.println("Program Closing Down"); System.exit(0);} else System.out.println("Unknown command"); } } public void addEntry() { BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in)); String forename = ""; String surname = ""; String street = ""; String city = ""; String county = ""; String country = ""; String post = ""; if(top == MAXENTRIES){ System.out.println("Address Book is full"); return; } //asks the user for the data of the address book try{ System.out.print("Forename: "); forename = keyIn.readLine(); System.out.print("Surname: "); surname = keyIn.readLine(); System.out.print("Street: "); street = keyIn.readLine(); System.out.print("City: "); city = keyIn.readLine(); System.out.print("County: "); county = keyIn.readLine(); System.out.print("Country: "); country = keyIn.readLine(); System.out.print("Postcode: "); post = keyIn.readLine(); }catch(Exception e){ System.out.println(e); System.exit(0); } Name name = new Name(forename, surname); Postcode postcode = new Postcode(post); Address address = new Address(street, city, county, country); } }
Does your code compile without errors?
Gamb1t (August 25th, 2011)