it looks like case 1, reading the data from a text doc is doing what it supposed to do (coz if i put the output lines under case 1 it works) however case2 doesn't have anything in the nameBox[] .. it didn't get the array index from case 1... any suggestion? thanks very much

public class Namebody //extends Name
{
	public static void main(String[] args)
	{
		System.out.println("<<Welcome to the personal information database>>");
		System.out.println("Please operate by the following options:");
		int option =0;
		int totalName=0;
		
		while(option!=9)
		{
			System.out.println("1.Load data from a file you choose.");
			System.out.println("2.See all the data.");
			System.out.println("3.Search the data.");
			System.out.println("4.Sort the data.");
			System.out.println("5.Edit the data");
			System.out.println("6.Add data");
			System.out.println("7.Delete data.");
			System.out.println("8.Save data");
			System.out.println("9.Exit out.");
			System.out.println();
			System.out.println("Select an option:");
			
			Scanner optionChoice = new Scanner(System.in);
			option = optionChoice.nextInt();
			Name nameBox[]= new Name[500];
	
	
		switch(option)
		{
			case 1:
			{
				/*
				readData(nameBox);
				*/
				int inID;
				int count=0;
				String inLastname, inFirstname,inPhone;
				double inPrice;
				String filename=null;
				Scanner reader = null;
				Scanner keyboard = new Scanner(System.in);
				
				System.out.println("Please give me the file name.");
				filename= keyboard.nextLine();
			
				try
				{
					reader = new Scanner(new FileReader(filename));
				}
			
				catch(FileNotFoundException e)
				{
					System.out.println("File not found!");
					System.exit(0);
				}
				
				while(reader.hasNextLine())
				{
					inID=reader.nextInt();
					inLastname= reader.next();
					inFirstname= reader.next();
					inPhone= reader.next();
					inPrice= reader.nextDouble();
					
					Name temp = new Name(inID, inLastname, inFirstname, inPhone, inPrice);
				
					nameBox[count]= temp;
					count++;
				}
				break;
				/*
				totalName= getTotalName(nameBox);
				System.out.println("total names are "+totalName);
				break;
				*/
			}
			
			case 2:
			{
				/*
				System.out.println(totalName);
				showData(nameBox, totalName);
				
				break;
				*/
				for(int i=0; i<totalName; i++)
				{
					nameBox[i].output();
				}
				break;
			}
			
			
			case 9:
			{
				System.out.println("Good Bye");
				System.exit(0);
			}
			
			default:
			{
				System.out.println("This is not an vaild option.");
				
			}
		}
		
		
	
	}
	} //for the while loop
while(option!=9) {

Name nameBox[]= new Name[500];

}

You create a new nameBox every time you repeat the loop, so the first time you are in the loop you give values to the local nameBox, but when the loop executes again, you create again a new nameBox (new Name[500]) that naturally hasn't anything inside.
Put the declaration of nameBox outside the while-loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.