I am trying to create a double array with values from two columns in java and it is not recognizing my worksheet.
I think my path name may be the issue, except that this is copied and pasted from the directory. (Except for the extra slashes of course). Any pointers in this direction would be helpful.
Here is my code:
The exception is being thrown by the line "XSSFWorkbook workbook = new XSSFWorkbook(fis);
package adina.twitter;
import java.io.IOException;
import java.util.Iterator;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.lang.Iterable;
public class ReadFile {
public static void main(String[] args) throws IOException {
final String FILE_PATH = "C:\\Users\\silbeab1\\Documents\\seedsActivity12Junv2.xlsx";
String fileSheet = "screen_name-user_id";
String[][] snId = null;
try{
FileInputStream fis = new FileInputStream(new File(FILE_PATH));
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet worksheet = workbook.getSheet(fileSheet);
boolean flag = true;
System.out.println(flag);
for (int x = 0; flag == true; x++){
for (int y = 0; y < 2; y++){
String test = worksheet.getRow(x).getCell(y).toString();
if (test != null){
snId[x][y] = test;
}
else{
flag = false;
}
}
}
}
catch (Exception e){
System.out.printf("Cannot open %s \n error: %s",FILE_PATH,e);
}
}
}
and here is my output: Cannot open C:\Users\silbeab1\Documents\seedsActivity12Junv2.xlsx error: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
Here is the full stack trace:
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:162)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:271)
at adina.twitter.ReadFile.main(ReadFile.java:29)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
... 4 more
Caused by: java.io.CharConversionException: Characters larger than 4 bytes are not supported: byte 0xa6 implies a length of more than 4 bytes
at org.apache.xmlbeans.impl.piccolo.xml.UTF8XMLDecoder.decode(UTF8XMLDecoder.java:162)
at org.apache.xmlbeans.impl.piccolo.xml.XMLStreamReader$FastStreamDecoder.read(XMLStreamReader.java:762)
at org.apache.xmlbeans.impl.piccolo.xml.XMLStreamReader.read(XMLStreamReader.java:162)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yy_refill(PiccoloLexer.java:3477)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(PiccoloLexer.java:3962)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(Piccolo.java:1290)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(Piccolo.java:1400)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:714)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3479)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1277)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1264)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.SharedStringsTable.readFrom(SharedStringsTable.java:119)
at org.apache.poi.xssf.model.SharedStringsTable.<init>(SharedStringsTable.java:106)
... 9 more