This will be the first post of me life on a forum of any type so please bare with me, and I will learn the proper etiquette.
I am working on an Address book program for a class I am in.
I am getting a " Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method menu() cannot be referenced from a static context at addressbook.AddressBook.main" that I can not figure out.
I need a point in the right direction.
I have read and reread about instance variables trying to figure this out.
In order to get everything flying I have to start it from my main() which must be static, but none of my methods are static and cannot be accessed from a static context.
my code follows.
AddressBook.java
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package addressbook; import java.util.Scanner; /** * * @author Eagle */ public class AddressBook { /** * @param args the command line arguments */ public static void main(String[] args) { menu(); } public void menu() { Scanner sIn = new Scanner(System.in); //Menu System.out.println("----/ / / MENU \\ \\ \\----"); System.out.println(); System.out.println("1.) Add Buisness Contact "); System.out.println("2.) Add Personal Contact "); System.out.println("3.) Display Buisness Contacts "); System.out.println("4.) Display Personal Contacts "); System.out.println("5.) Quit "); int choice = sIn.nextInt(); if (choice == 1) { BusinessContact.addContact(); } else if (choice == 2) { PersonalContact.addContact(); } else if (choice == 3) { BusinessContact.printContact(); } else if (choice == 4) { PersonalContact.printContact(); } else if (choice == 5) { System.exit(0); } else { System.out.println("Please enter a number between 1 and 5."); } } }
Contact.java
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package addressbook; import java.util.ArrayList; import java.util.Scanner; /** * * @author Eagle */ public abstract class Contact { private String Fname; private String Lname; private String Add; private String Pnumber; private String Eadd; Scanner stdIn = new Scanner(System.in); public Contact(String FirstName, String LastName, String Address, String PhoneNumber, String EmailAddress){ Fname = FirstName; Lname = LastName; Add = Address; Pnumber = PhoneNumber; Eadd = EmailAddress; } abstract void addContact(); public void printContact(){ System.out.println("Name: "+ Fname + " " + Lname); System.out.println("Address: " + Add); System.out.println("Phone: " + Pnumber); System.out.println("E-Mail Address: " + Eadd); } String getFname(){ return Fname; } void setFname(String newValue){ Fname = newValue; } String getLname(){ return Lname; } void setLname(String newValue){ Lname = newValue; } String getAdd(){ return Add; } void setAdd(String newValue){ Add = newValue; } String getPnumber(){ return Pnumber; } void setPnumber(String newValue){ Pnumber = newValue; } String getEadd(){ return Eadd; } void setEadd(String newValue){ Eadd = newValue; } }
PersonalContact.java
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package addressbook; /** * * @author Eagle */ public class PersonalContact extends Contact { private String Dob; public PersonalContact(String FirstName, String LastName, String Address, String PhoneNumber, String EmailAddress, String DateofBirth) { super(FirstName, LastName, Address, PhoneNumber, EmailAddress); Dob = DateofBirth; } /** * */ @Override public void addContact(){ } String getDob(){ return Dob; } void setDob(String newValue){ Dob = newValue; } @Override public void printContact() { super.printContact(); System.out.println("Date of Birth: " + Dob); } }
BusinessContact.java
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package addressbook; /** * * @author Eagle */ public class BusinessContact extends Contact { private String Jtitle; private String Org; public BusinessContact(String FirstName, String LastName, String Address, String PhoneNumber, String EmailAddress, String JobTitle, String Organization) { super(FirstName, LastName, Address, PhoneNumber, EmailAddress); Jtitle = JobTitle; Org = Organization; } @Override public void printContact(){ super.printContact(); System.out.println("Job title: " + Jtitle); System.out.println("Organization: " + Org); } @Override public void addContact(){ } String getJtitle(){ return Jtitle; } void setJtitle(String newValue){ Jtitle = newValue; } String getOrg(){ return Org; } void setOrg(String newValue){ Org = newValue; } }
Thank you for any help
James K "Soaring Eagle" Linderman