Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: null pointer exception helpppppppppp

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation null pointer exception helpppppppppp

    \\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();
    }

    }
    }
    Last edited by Norm; May 5th, 2013 at 05:58 AM. Reason: Duplicate


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: null pointer exception helpppppppppp

    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: null pointer exception helpppppppppp

    java.lang.NullPointerException
    at bentupdate.main(bentupdate.java:62)
    at __SHELL0.run(__SHELL0.java:6)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:725 )
    I am new user and i dont know this site if you still want the code download it from ..first create a excel file in "C:\\temp\\testPOIWrite.xls"
    download the code [URL="http://www.mediafire.com/view/?9gmmh3yy49ub96x"]

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: null pointer exception helpppppppppp

    java.lang.NullPointerException
    at bentupdate.main(bentupdate.java:62)
    There is a variable with a null value on line 62. Look at line 62 in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line 62 and print out the values of all the variables on that line.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need Help with Null Pointer Exception
    By kendraheartt in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 23rd, 2012, 02:20 PM
  2. [SOLVED] Null Pointer Exception
    By wltrallen2 in forum Object Oriented Programming
    Replies: 7
    Last Post: May 27th, 2012, 10:21 AM
  3. Null Pointer exception
    By Demetrius82 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 2nd, 2011, 07:32 PM
  4. Null Pointer Exception Help !!
    By AlterEgo1234 in forum Member Introductions
    Replies: 1
    Last Post: March 27th, 2011, 10:07 AM
  5. Null pointer exception
    By Wrathgarr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2010, 12:48 AM