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 2 of 2

Thread: What is the wrong with this code?

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post What is the wrong with this code?

    When i am executing this code, i am getting null pointer Exception.pls help me to fix the problem.

    Here is the code:
    try{
    int rows1=CustomerPaymentRow_Table.getRowCount();
    for(int i=0;i<rows1;i++){
    Object value=CustomerPaymentRow_Table.getModel().getValue At(i, 11);
    String state=value.toString();
    System.out.println(state);
    if(state=="true")
    {
    //
    Object value0=CustomerPaymentRow_Table.getModel().getValu eAt(i,0);
    InvoiceNo =value0.toString();
    //
    Object value1=CustomerPaymentRow_Table.getModel().getValu eAt(i,1);
    InvoiceDate = value1.toString();
    //
    Object value2=CustomerPaymentRow_Table.getModel().getValu eAt(i,2);
    AmountDue=value2.toString();
    //
    Object value3=CustomerPaymentRow_Table.getModel().getValu eAt(i,3);
    Discount=value3.toString();
    //
    Object value10=CustomerPaymentRow_Table.getModel().getVal ueAt(i,4);
    NetAmt=value10.toString();
    //
    Object value4=CustomerPaymentRow_Table.getModel().getValu eAt(i,5);
    NetPay=value4.toString();
    //
    Object value5=CustomerPaymentRow_Table.getModel().getValu eAt(i,6);
    RowBalance=value5.toString();
    double Row_Baldouble = Double.parseDouble(RowBalance);
    //
    Object value6=CustomerPaymentRow_Table.getModel().getValu eAt(i,7);
    Paymentmode=value6.toString();
    //
    Object value7=CustomerPaymentRow_Table.getModel().getValu eAt(i,8);
    ChqNo=value7.toString();
    //
    Object value8=CustomerPaymentRow_Table.getModel().getValu eAt(i,9);
    ChqDate=value8.toString();
    //
    Object value9=CustomerPaymentRow_Table.getModel().getValu eAt(i,10);
    Bank=value9.toString();
    //
    docentry=DocEntry_FTextField.getText();
    //Inserting data into Receipt_hdr and Receipt_row
    String sql1=("insert into receipt_row(DocEntry,ReceiptNo,InvoiceNo,InvoiceDa te,AmountDue,DiscountPerc,RowBalance,NetAmount,Pay Mode,NetPay,ChqNo,ChqDate,Bank) values('"+docentry+"','"+docentry+"','"+InvoiceNo+ "','"+InvoiceDate+"','"+AmountDue+"','"+Discount+" ','"+RowBalance+"','"+NetAmt+"','"+Paymentmode+"', '"+NetPay+"','"+ChqNo+"','"+ChqDate+"','"+Bank+"') ");
    n=st.executeUpdate(sql1);
    }
    }----------------
    //Checking that receipt_row,customercode,customername,compname for null values
    if((n != 0)&&(cus_id.length()!=0)&&(cus_name.length()!=0)&& (comp_name.length()!=0))
    {
    System.out.println("condition checked");
    String sql=("insert into receipt_hdr(DocEntry,DocDate,DocStatus,CardCode,Ca rdName,SMCode,Remarks,DocTotal,DiscountPerc,NetTot al,BaseRef,BeatCode,CompCode) values('"+docentry+"','"+docdate+"','"+DocStatus+" ','"+cus_id+"','"+cus_name+"','"+comp_name+"','"+r emarks+"','"+doc_total+"','"+discount_hdr+"','"+ne t_total+"','"+base_ref+"','"+beatcode+"','"+comp_n ame+"')");
    System.out.println("insert");
    m=st.executeUpdate(sql);
    System.out.println("hdr inserted");
    JOptionPane.showMessageDialog(null,"Payment Done!");
    }
    else{
    JOptionPane.showMessageDialog(null,"Provide Mandatory Informations");
    }
    }
    catch(Exception e) {
    System.out.println(e);
    }

    In this code,code is successfully executing till that dotted line.After that only code is not executing.why?

    pls help me...
    Last edited by Subhasri; September 30th, 2011 at 12:32 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: What is the wrong with this code?

    You're getting a NullPointerException, which means you're trying to dereference a null value. That means you're probably trying to call a function on variable whose value is null.

    Have you stepped through this with a debugger to figure out which variable is null? Even adding some print statements would go a long way. Hint: you can check for null just by testing whether a variable == null.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. What is wrong in the code
    By Rajiv in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: July 29th, 2011, 01:09 PM
  2. What is Wrong with my code
    By xew123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 04:59 AM
  3. What's wrong with my code?
    By lindmando in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 7th, 2011, 11:13 PM
  4. What is wrong with my code?
    By phantom06 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 3rd, 2011, 05:21 AM
  5. what's wrong in this code
    By Aravind in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2011, 03:38 AM