Results 1 to 5 of 5
- 07-30-2011, 06:21 PM #1
java.lang.NullPointerException
HI,
Thank you for your attention.
Today, i am joined java forums.
I got null pointer exception.
Code:
With Regards,Java Code:import java.awt.*; import javax.swing.*; import javax.swing.table.*; import java.sql.*; public class Confidence extends JFrame { Object[] data = new Object[1]; String s[]={"Confidence"}; int num[]; String sql[]; int i,j,k; DefaultTableModel d = new DefaultTableModel(); JTable jtable1 = new JTable(d); JFrame frame = new JFrame(); public Confidence() { setVisible(true); setSize(300, 300); setLocation(100, 100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for(int c = 0; c < 1; c++) { d.addColumn(s[c]); } try { Connection con=null; Statement st1=null; ResultSet rs[]=null; PreparedStatement pst=null; int p1m=0; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("Jdbc:Odbc:Eight","sa" ,""); System.out.println("New Connection Create"); sql[3]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y' and Debt='N'"; sql[4]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y' and Debt='Y'"; sql[5]="SELECT count(P1) FROM CustomerTable WHERE Gender='M' and p1='Y' and Debt='N'"; sql[0]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y'"; sql[1]="SELECT count(P1) FROM CustomerTable WHERE Gender='F' and p1='Y'"; sql[2]="SELECT count(P1) FROM CustomerTable WHERE Gender='M' and p1='Y'"; j=3; for(i=0;i<=2;i++) { rs[i]=st1.executeQuery(sql[i]); if (rs[i].next()) { num[i]= rs[i].getInt(1); rs[i].close(); } rs[j]=st1.executeQuery(sql[j]); { if (rs[j].next()) { int number = rs[j].getInt(1); data[1]=number+"/"+num[k]; k++; } rs[j].close(); j++; } d.addRow(data); } } catch(Exception ex) { System.out.println(ex); } add(new JScrollPane(jtable1)); setVisible(true); } public static void main(String args[]) { Confidence rw = new Confidence(); } }
NandhiniLast edited by Fubarable; 07-30-2011 at 07:26 PM. Reason: quote tags changed to code tags
-
I recommend you edit your post above and add code tags so that the code is readable. Also you will want to indicate which line throws the NullPointerException.
- 07-30-2011, 07:10 PM #3
Ok.Thank you.
I don't know which line throws the NullPointerException.
Output:
With Regards and Respects,New Connection Create
java.lang.NullPointerException
BUILD SUCCESSFUL (total time: 13 minutes 49 seconds)
Nandhini.
-
Change your catch block from this:
to this:Java Code:} catch (Exception ex) { System.out.println(ex); }
Then post your exception message here and see if the exception message indicates which line is throwing the NPE (NullPointerException).Java Code:} catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }
I also edited your first post and changed your quote tags into code tags.
- 08-05-2011, 06:35 AM #5
Similar Threads
-
java.lang.NullPointerException and i don't know why
By Qubes in forum New To JavaReplies: 15Last Post: 01-13-2011, 06:28 PM -
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 1Last Post: 02-27-2009, 12:36 PM -
java.lang.NullPointerException
By stevemcc in forum AWT / SwingReplies: 2Last Post: 02-08-2008, 09:01 AM -
java.lang.NullPointerException
By ravian in forum New To JavaReplies: 1Last Post: 01-13-2008, 07:39 PM -
java.lang.NullPointerException
By Felissa in forum Advanced JavaReplies: 1Last Post: 07-05-2007, 06:02 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks