\\Dear sir plz help im getting null pointer exception
\\if you want to execute this code createa file testPOIWrite.xls in c:\temp
import java.io.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
class bentupdate
{
static String [][] excelData;
static int nop=0,advamt,balamt,amt;
static String cus="",pl="",typ="",db="",dd="";
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter name of customer");
cus=sc.next();
System.out.println("Enter place");
pl=sc.next();
System.out.println("Enter type ofplant");
typ=sc.next();
System.out.println("Enter date of booking in dd/mm/yy");
db=sc.next();
System.out.println("Enter date of delivery in dd/mm/yy");
dd=sc.next();
System.out.println("Enter no. of plants");
nop=sc.nextInt();
System.out.println("Enter amt");
amt=sc.nextInt();
System.out.println("Enter advamce amt");
advamt=sc.nextInt();
System.out.println("Enter Balance amt");
balamt=sc.nextInt();
// --------------------------------------------------------------------------
try {
FileInputStream file = new FileInputStream(new File("C:\\temp\\testPOIWrite.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
Cell cell=null;
int x=1,y=0;
for(x=1;x<200;x++)
{
cell=sheet.getRow(x).getCell(0);
if(cell.getCellType() == Cell.CELL_TYPE_BLANK)
{
//Update the value of cell
sheet.getRow(x).getCell(0).setCellValue(x);
cell = sheet.getRow(x).getCell(0);
cell.setCellValue(x);
cell = sheet.getRow(x).getCell(1);
cell.setCellValue(cus);
cell = sheet.getRow(x).getCell(2);
cell.setCellValue(pl);
cell = sheet.getRow(x).getCell(3);
cell.setCellValue(typ);
cell = sheet.getRow(x).getCell(4);
cell.setCellValue(db);
cell = sheet.getRow(x).getCell(5);
cell.setCellValue(nop);
cell = sheet.getRow(x).getCell(6);
cell.setCellValue(amt);
cell = sheet.getRow(x).getCell(7);
cell.setCellValue(advamt);
cell = sheet.getRow(x).getCell(8);
cell.setCellValue(balamt);
cell = sheet.getRow(x).getCell(9);
cell.setCellValue(dd);
FileOutputStream outFile =new FileOutputStream(new File("C:\\temp\\testPOIWrite.xls"));
workbook.write(outFile);
outFile.close();
file.close();
System.exit(0);
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch (NullPointerException e) {
e.printStackTrace();
}
}
}
\\Dear sir plz help im getting null pointer exception
\\if you want to execute this code createa file testPOIWrite.xls in c:\temp
import java.io.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
class bentupdate
{
static String [][] excelData;
static int nop=0,advamt,balamt,amt;
static String cus="",pl="",typ="",db="",dd="";
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter name of customer");
cus=sc.next();
System.out.println("Enter place");
pl=sc.next();
System.out.println("Enter type ofplant");
typ=sc.next();
System.out.println("Enter date of booking in dd/mm/yy");
db=sc.next();
System.out.println("Enter date of delivery in dd/mm/yy");
dd=sc.next();
System.out.println("Enter no. of plants");
nop=sc.nextInt();
System.out.println("Enter amt");
amt=sc.nextInt();
System.out.println("Enter advamce amt");
advamt=sc.nextInt();
System.out.println("Enter Balance amt");
balamt=sc.nextInt();
// --------------------------------------------------------------------------
try {
FileInputStream file = new FileInputStream(new File("C:\\temp\\testPOIWrite.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
Cell cell=null;
int x=1,y=0;
for(x=1;x<200;x++)
{
cell=sheet.getRow(x).getCell(0);
if(cell.getCellType() == Cell.CELL_TYPE_BLANK)
{
//Update the value of cell
sheet.getRow(x).getCell(0).setCellValue(x);
cell = sheet.getRow(x).getCell(0);
cell.setCellValue(x);
cell = sheet.getRow(x).getCell(1);
cell.setCellValue(cus);
cell = sheet.getRow(x).getCell(2);
cell.setCellValue(pl);
cell = sheet.getRow(x).getCell(3);
cell.setCellValue(typ);
cell = sheet.getRow(x).getCell(4);
cell.setCellValue(db);
cell = sheet.getRow(x).getCell(5);
cell.setCellValue(nop);
cell = sheet.getRow(x).getCell(6);
cell.setCellValue(amt);
cell = sheet.getRow(x).getCell(7);
cell.setCellValue(advamt);
cell = sheet.getRow(x).getCell(8);
cell.setCellValue(balamt);
cell = sheet.getRow(x).getCell(9);
cell.setCellValue(dd);
FileOutputStream outFile =new FileOutputStream(new File("C:\\temp\\testPOIWrite.xls"));
workbook.write(outFile);
outFile.close();
file.close();
System.exit(0);
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch (NullPointerException e) {
e.printStackTrace();
}
}
}