I need a help with the use of POI apache, in my application I need to perform a query inside a worksheet, this query checks if there is a value in the worksheet, this query is ok, below I'll put the code simulating a value for make it easier to explain.
Follow the verification code;
InputStream ExcelFileToRead = new FileInputStream(new File("sdcard/AperamApps/DBQ/historico/historico.xls"));
HSSFWorkbook wb = new HSSFWorkbook(ExcelFileToRead);
HSSFSheet sheet=wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;
Iterator rows = sheet.rowIterator();
while (rows.hasNext())
{
row=(HSSFRow) rows.next();
Iterator cells = row.cellIterator();
while (cells.hasNext())
{
cell=(HSSFCell) cells.next();
if (cell.getStringCellValue() != "google")
{
Toast.makeText(getApplicationContext(),
"Valor GOOGLE encontrado",
Toast.LENGTH_LONG).show();
//PRECISO REMOVER A LINHA QUE POSSUI UMA CELULA COM COM O VALOR GOOGLE
}
}
ExcelFileToRead.close();
System.out.println();
}
My code is able to do the verification, however, if the condition returns true to the line where that cell is, I tried to use sheet.deleteRow(row);
inside the if plus the application generates error.
Following the logcat: link
12-01 15:34:37.851: I/dalvikvm(1632): Could not find method org.apache.commons.codec.digest.DigestUtils.md5, referenced from method org.apache.poi.hssf.usermodel.HSSFWorkbook.addPicture
12-01 15:34:37.851: W/dalvikvm(1632): VFY: unable to resolve static method 4982: Lorg/apache/commons/codec/digest/DigestUtils;.md5 ([B)[B
12-01 15:34:37.851: D/dalvikvm(1632): VFY: replacing opcode 0x71 at 0x0004
12-01 15:34:37.943: D/AndroidRuntime(1632): Shutting down VM
12-01 15:34:37.943: W/dalvikvm(1632): threadid=1: thread exiting with uncaught exception (group=0xa4c4b648)
12-01 15:34:37.947: E/AndroidRuntime(1632): FATAL EXCEPTION: main
12-01 15:34:37.947: E/AndroidRuntime(1632): java.lang.RuntimeException: Unable to start activity ComponentInfo{pro.kondratev.androidreadxlsx/matheus.arruda.aperam.controleDBQmestre.classe_master}: java.lang.IllegalArgumentException: Specified row does not belong to this sheet
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.os.Looper.loop(Looper.java:137)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-01 15:34:37.947: E/AndroidRuntime(1632): at java.lang.reflect.Method.invokeNative(Native Method)
12-01 15:34:37.947: E/AndroidRuntime(1632): at java.lang.reflect.Method.invoke(Method.java:525)
12-01 15:34:37.947: E/AndroidRuntime(1632): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-01 15:34:37.947: E/AndroidRuntime(1632): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-01 15:34:37.947: E/AndroidRuntime(1632): at dalvik.system.NativeStart.main(Native Method)
12-01 15:34:37.947: E/AndroidRuntime(1632): Caused by: java.lang.IllegalArgumentException: Specified row does not belong to this sheet
12-01 15:34:37.947: E/AndroidRuntime(1632): at org.apache.poi.hssf.usermodel.HSSFSheet.removeRow(HSSFSheet.java:279)
12-01 15:34:37.947: E/AndroidRuntime(1632): at matheus.arruda.aperam.controleDBQmestre.classe_master.validar(classe_master.java:1608)
12-01 15:34:37.947: E/AndroidRuntime(1632): at matheus.arruda.aperam.controleDBQmestre.classe_master.ler(classe_master.java:682)
12-01 15:34:37.947: E/AndroidRuntime(1632): at matheus.arruda.aperam.controleDBQmestre.classe_master.onCreate(classe_master.java:203)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.Activity.performCreate(Activity.java:5133)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-01 15:34:37.947: E/AndroidRuntime(1632): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
12-01 15:34:37.947: E/AndroidRuntime(1632): ... 11 more