I am stuck. I don't know how to read a data value from a file to class object. I have to do it for three references for the class Employee. This is what I have so far as of now:
public void displayEmployees(View view)
{
EditText edt1;
TextView tv;
String urlfile; //For variable that stores the user input for url address
edt1 = (EditText) findViewById(R.id.edit_file);
tv = (TextView) findViewById(R.id.text_main);
//Declare references to class Employee
Employee e1;
Employee e2;
Employee e3;
//Create three objects for class Employee
e1 = new Employee();
e2 = new Employee();
e3 = new Employee();
//Retrieve what user has input
urlfile = edt1.getText().toString();
//Open and read the data values from a file on the web
try
{
//Create URL object
URL file_url = new URL(urlfile);
//try to open the file from the web
Scanner fsc = new Scanner(file_url.openStream());
}
catch(IOException e)
{
tv.setText("Error: Invalid URL Address or File Does Not Exist");
}
}
And, this is what the class looks like:
public class Employee {
private String name;
private String id;
private double salary;
private String office;
private String extension;
private int yearsofservice;
public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
public String getId()
{
return id;
}
public void setId(String ID)
{
id = ID;
}
public double getSalary()
{
return salary;
}
public void setSalary(double Salary)
{
salary = Salary;
}
public String getOffice()
{
return office;
}
public void setOffice(String Office)
{
office = Office;
}
public String getExt()
{
return extension;
}
public void setExt(String Extension)
{
extension = Extension;
}
public int getYearsOfServ()
{
return yearsofservice;
}
public void setYearsOfServ(int YearsOfService)
{
yearsofservice = YearsOfService;
}
}// end class Employee
Lastly, the file that I am reading from look like this, for example:
Joe Bob 00001 9000.00 Campus Hall 9999 5