Please can someone elp me with this peice of code below, i am trying to get the user to enter a an address, search through the string arrary address, if its found then stop if not found then get them to input data for the rest of the arrays. i can get it to work if i pre set values into the address string
e.g. String [] address = {"rob st","king rd","mary st");
but i need to get the user to enter the data for that too, any help would be great
i get this message after entering an address for
String addressnosearch = Text.readString ("Input name to search for, * to finish");
Exception in thread "main" java.lang.NullP ointerException
at test4.main(test 4.java:31)
Process exited with exit code 1.
e.g. String [] address = {"rob st","king rd","mary st");
but i need to get the user to enter the data for that too, any help would be great
Code:
import java.io.*;
public class test4
{
public static void main(String[] args) throws IOException
{
final int maxStudents = 10;
String [] address = new String [maxStudents];
String [] firstname = new String [maxStudents];
String[] lastname = new String [maxStudents];
String [] telno = new String [maxStudents];
int activeEntries = 0;
boolean found = false;
int i = 0;
String addressnosearch = Text.readString("Input name to search for, * to finish");
while ( !addressnosearch.equals("*") )
{
found = false;
i = 0;
while ( !found && i < address.length)
{
if (address[i].equals(addressnosearch) ) //could use == true
{
found = true;
}
else
{
i++;
}//end-if
}//end-while
if (found == true)
{
Text.showMessage ( addressnosearch + " was found in the array");
}
else
{
address[activeEntries] = addressnosearch;
firstname[activeEntries] = Text.readString("Enter First Name " );
lastname[activeEntries] = Text.readString("Enter Last Name " );
telno[activeEntries] = Text.readString("Enter Telephone no " );
activeEntries = activeEntries + 1;
}//end-if
}//end-while
System.exit(0);
}//main
}//LinearSearch
i get this message after entering an address for
String addressnosearch = Text.readString ("Input name to search for, * to finish");
Exception in thread "main" java.lang.NullP ointerException
at test4.main(test 4.java:31)
Process exited with exit code 1.
Comment