-2

i Tried to get data from excel in java. if i execute it as normal java program i am getting data from excel and it is getting printed in console.But when i put it my Robotium test project, i am getting null pointer exception(file or directory not found).

public void testCanOpenSettings() throws IOException, Exception {
    loginvalid();   
}

public void Eula() {

    if(solo.searchText("Accept"))
    { 
        System.out.println(" Eula accept");
        solo.clickLongOnText("Accept"); 
    }
}

public void loginvalid() throws IOException  {
    String username;
    String password;
    solo.sendKey(Solo.MENU);
    solo.sleep(3000);
    solo.clickLongOnText("Sign In");
    solo.sleep(3000);
    //solo.clearEditText(0);
    username = Readexcel(0,0);
    password = Readexcel(0,1);
    solo.enterText(0,username);
    solo.enterText(1, password);
    solo.clickOnCheckBox(0);
    solo.clickLongOnText("Sign In");

}
public static String Readexcel(int row,int col) throws IOException  { 
    String filename = "C://Documents//Robo//robo1.xls";
    String s = "";

    try
    {
        FileInputStream fis = new FileInputStream(filename);
        HSSFWorkbook myWorkBook = new HSSFWorkbook(fis);
        HSSFSheet mySheet = myWorkBook.getSheetAt(0);
        HSSFRow row1 = mySheet.getRow(row);
        HSSFCell cell1 = row1.getCell(col);
        s = cell1.getRichStringCellValue().getString();
        System.out.println("Cell 1 : "+s);
        Log.d("cell value",s );

        System.out.println(s);
            return s;

    }
    catch (IOException e) {
        e.printStackTrace();strong text
        return null;
    } 

    }
}
tibtof
  • 7,857
  • 1
  • 32
  • 49
Vaishnavi
  • 23
  • 4

1 Answers1

1

You are reading the file C://Documents//Robo//robo1.xls, that is stored on your computers HardDrive which your phone of course can't access. You need to put the file on your phone SD-card and use the uri to that location instead:

File storage = Environment.getExternalStorageDirectory() //Returns sd-card
String filename = "robo1.xls"; //file name, may have path separators
File myfile = new File(storage, filename);
//myfile is now a File object that you can use, to get the path, use myfile.getAbsolutePath()
Jave
  • 31,598
  • 14
  • 77
  • 90
  • @Vaishnavi Thank you :) Please accept the answer by clicking the checkmark under the score to the left. – Jave Jun 20 '12 at 17:40