Problem that I am facing right now is that I want import an excel file and pass it to another class like this:
package cal;
import java.util.Scanner;
public class CalendarMain {
public static void main(String[] args) {
Scanner link = new Scanner(System.in);
System.out.println("Please insert the raw file link: ");
String excellink = link.nextLine();
link.close();
String[] excelLink = new String[] { excellink };
ShiftSetting.main(excelLink);
}
}
There was no problem for compile and run it through command prompt but when paste the raw file link into the command prompt and click enter, it give me this error:
C:\Users\User\eclipse-workspace\Calendar_v1\src>java cal.CalendarMain cal.ShiftSetting cal.PHNames
Please insert the raw file link:
C:\Users\User\Desktop\WORK\2019raw.xlsx
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Row
at cal.CalendarMain.main(CalendarMain.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Row
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
FYI, this problem never arise when I run it on Eclipse. But when I try run on command prompt, it give me this error. Line 16 is actually this line : ShiftSetting.main(excelLink);
I provide also the ShiftSetting.java file
package cal;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ShiftSetting {
public static void main(String[] excelLink) {
ArrayList<String> shiftname = new ArrayList<String>();
ArrayList<String> shiftcode = new ArrayList<String>();
try {
FileInputStream file = new FileInputStream(new File("C:\\Users\\User\\Desktop\\WORK\\shiftnameall.xlsx"));
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
DataFormatter formatter = new DataFormatter();
String cellValue = null;
for (int rowNum = 0; rowNum < sheet.getLastRowNum() + 1; rowNum++) {
Row r = sheet.getRow(rowNum);
String val = null;
for (int m = 0; m < r.getLastCellNum(); m = m + 2) {
Cell cell = r.getCell(m);
val = formatter.formatCellValue(cell);
shiftname.add(val);
}
}
for (int rowNum = 0; rowNum < sheet.getLastRowNum() + 1; rowNum++) {
Row r = sheet.getRow(rowNum);
String val = null;
for (int m = 1; m < r.getLastCellNum(); m++) {
Cell cell = r.getCell(m);
val = formatter.formatCellValue(cell);
shiftcode.add(val);
}
}
} catch (Exception e) {
e.printStackTrace();
}
/* PHDatesArray.main(excelLink, shiftname, shiftcode); */
}
}
Anyone has idea how to solve this problem?