Urgent: Cannot Find Symbol!
I tried compiling my personal contacts database program, but I have nothing
but cannot find symbol errors!
Should I be instantiating an object more often than once? If not, what is
wrong with this code?
Please reply asap!
-----------
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Contacts
{
String name;
String phone;
String addy;
String[] namesDB = new String[100];
int index=0;
public Contacts (String fullName, String phoneNo, String address)
{
name=fullName;
phone=phoneNo;
addy=address;
}
public String printName(String fullName)
{
for (index=0;index<100;index++)
{
if (fullName==namesDB[index])
System.out.println(namesDB[index]);
else
index++;
}
return namesDB[index];
}
public String deleteName(String fullName)
{
for (index=0;index<100;index++)
{
if (fullName==namesDB[index])
{
namesDB[index]= "0";
System.out.println("Record Deleted.");
}
else
index++;
}
return namesDB[index];
}
static String stripQuo(String str)
{
if (str.startsWith("\""))
{
str = str.substring(1, str.length());
}
if (str.endsWith("\""))
{
str = str.substring(0, str.length() - 1);
}
return str;
}
public static void main(String[] args)
{
String EMPTY = "Empty";
int index=0;
String[] namesDB = new String[100];
String fullName, phoneNo, address;
for (int i=0; i<100; i++)
{
Contacts w = new Contacts("-1", "-1", "-1");
w.namesDB[i]=EMPTY;
i++;
}
//Creating Writable File, PCD=Personal Contacts Database
try
{
PrintWriter writetoFile=new PrintWriter(new FileOutputStream("PCDFile.txt")
);
BufferedReader readFile=null;
readFile = new BufferedReader(new FileReader("PCDFile.txt"));
}
catch(FileNotFoundException ex)
{
System.out.println("Error opening PCDFile.txt");
System.exit(0);
}
catch(IOException gh)
{
System.out.println("Error reading from PCDFile.txt.");
System.exit(0);
}
//ADDING
if (args.length == 1)
{
String option=args[0];
if (option.equals("-a"))
{
for (int i=0;i<100; i++)
{
if(namesDB[i]==EMPTY)
{
System.out.println("Full Name: ");
Scanner keyboard = new Scanner(System.in);
fullName=keyboard.nextLine();
System.out.println("Phone: ");
phoneNo=keyboard.nextLine();
System.out.println("Address: ");
address=keyboard.nextLine();
Contacts w = new Contacts(fullName, phoneNo, address);
namesDB[i]="fullName/n" + "phoneNo/n" + "address/n";
writetoFile.println(namesDB[i]);
System.out.println(namesDB[i]);
}
else
index++;
}
}
//SEARCHING
else
{
option=stripQuo(option);
option=fullName;
String line= readFile.readLine();
for (index=0;index<100;index++)
{
if (line!=null)
{
if(line.equals(fullName))
{
Contacts w = new Contacts(fullName, phoneNo, address);
w.printName(fullName);
}
}
else
index++;
if (index==namesDB.length-1)
{
System.out.println("No record found for " + fullName + ".");
}
}
}
if (args.length == 2)
{
option=args[0];
fullName=args[1];
if (option.equals("-s"))
{
Contacts w = new Contacts(fullName, phoneNo, address);
fullName=w.stripQuo(fullName);
String line=readFile.readline();
for (index=0;index<100; index++)
{
if (line!=null)
{
if(line.equals(w.Contacts(fullName, phoneNo, address)))
{
w.printName(fullName);
}
}
else
index++;
if (index==namesDB.length-1)
{
System.out.println("No record found for " + fullName + ".");
}
}
}
else if (option.equals("-d"))
{
fullName=w.stripQuo(fullName);
String line=readFile.readline();
for (index=0;index<100; index++)
{
if (line!=null)
{
if(line.equals(w.Contacts(fullName, phoneNo, address)))
{
w.deleteName(fullName);
}
}
else if (index==namesDB.length-1)
System.out.println("No record found for " + fullName + ".");
else
index++;
}}
}
writetoFile.close();
readFile.close();
}
}
}
-------------------
Compiler Messages:
/Contacts.java:128: cannot find symbol
symbol : variable writetoFile
location: class Contacts
writetoFile.println(namesDB[i]);
^
/Contacts.java:141: cannot find symbol
symbol : variable readFile
location: class Contacts
String line= readFile.readLine();
^
/Contacts.java:175: cannot find symbol
symbol : method Contacts(java.lang.String,java.lang.String,java.la ng.String)
location: class Contacts
if(line.equals(w.Contacts(fullName, phoneNo, address)))
^
and etc..