SQLite java.lang.NullPointerException仅在select查询中

SQLite java.lang.NullPointerException仅在select查询中,java,sqlite,select,jdbc,Java,Sqlite,Select,Jdbc,我添加了sqlite-jdbc-3.7.2.jar来构建路径。我使用了插入查询。当我用记事本打开wellec.db时,我可以看到记录。但是我的选择不起作用 这里是WellInfo类属性 public Integer wellID; public Integer measurement; public String wellname; public Integer wellstatus; public String licenseno; public String gl; public Strin

我添加了sqlite-jdbc-3.7.2.jar来构建路径。我使用了插入查询。当我用记事本打开wellec.db时,我可以看到记录。但是我的选择不起作用

这里是WellInfo类属性

public Integer wellID;
public Integer measurement;
public String wellname;
public Integer wellstatus;
public String licenseno;
public String gl;
public String kb;
public String spuddate;
public String drillingenddate;
public String totaldepth;
public String notes;
public String easting;
public String northing;
public String coordinatesystem;
public Integer islogadd;
这是我的createtable sql

          Class.forName("org.sqlite.JDBC");
          c = DriverManager.getConnection("jdbc:sqlite:wellec.db");
          c.setAutoCommit(false);
          System.out.println("Opened database successfully");

          stmt = c.createStatement();

          String sql = "CREATE TABLE IF NOT EXISTS WELLINFO " +
                    "(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ," +
                    " WELLNAME           CHAR(90)    NOT NULL, " +
                    " WELLSTATUS   INT NOT NULL," +
                    " MEASUREMENT INT NOT NULL," +
                    " ISLOGADD INT NOT NULL," +
                    " GL           CHAR(50)    NOT NULL, " +
                    " KB           CHAR(50)    NOT NULL, " +
                    " SPUDDATE           CHAR(50)    NOT NULL, " +
                    " TOTALDEPTH           CHAR(50)    NOT NULL, " +
                    " LICENSENO           CHAR(50)    NOT NULL, " +
                    " DRILLINGENDDATE           CHAR(50)    NOT NULL, " +
                    " NOTES           CHAR(150)    NOT NULL, " +
                    " EASTING           CHAR(50)    NOT NULL, " +
                    " NORTHING           CHAR(50)    NOT NULL, " +
                    " COORDINATESYSTEM CHAR(50)    NOT NULL)";
          stmt.executeUpdate(sql);
...//other tables sql and stmt.executeUpdate(sql)
 stmt.close();
 c.commit();
这是我的insert查询,它正在工作。WellInfo wi as参数

        Connection c = null;
        Statement stmt = null;
        try {
          Class.forName("org.sqlite.JDBC");
          c = DriverManager.getConnection("jdbc:sqlite:wellec.db");
          c.setAutoCommit(false);
          System.out.println("Opened database successfully");

          stmt = c.createStatement();
          String sql = "INSERT INTO WELLINFO " +
                    "(ID, WELLNAME, WELLSTATUS , MEASUREMENT, ISLOGADD , GL, KB, SPUDDATE, TOTALDEPTH, " +
                    "LICENSENO , DRILLINGENDDATE, NOTES, EASTING, NORTHING, COORDINATESYSTEM) " +
                    "VALUES (NULL,'" + wi.wellname + "'," + wi.wellstatus + "," + wi.measurement + "," +
                            "" + wi.islogadd +",'" + wi.gl + "','" + wi.kb + "','" + wi.spuddate + "'," +
                                    "'" + wi.totaldepth + "','" + wi.licenseno + "','" + wi.drillingenddate + "', " +
                                            "'" + wi.notes + "','" + wi.easting + "','" + wi.northing + "','" + wi.coordinatesystem + "');";
          stmt.executeUpdate(sql);

          stmt.close();
          c.commit();

        } catch ( Exception e ) {
          System.err.println( e.getClass().getName() + ": " + e.getMessage() );
          System.exit(0);
        }
        System.out.println("Records created successfully");

        return 0;
这是我的选择

    Connection c = null;
    Statement stmt = null;
    WellInfo[] wi = new WellInfo[60000];
    WellInfo[] wi2 = new WellInfo[0];

    int i = 0;
    try {
      Class.forName("org.sqlite.JDBC");
      c = DriverManager.getConnection("jdbc:sqlite:wellec.db");
      //c.setAutoCommit(false);
      System.out.println("Opened database successfully");


      stmt = c.createStatement();
      ResultSet rs = stmt.executeQuery("select * from WELLINFO"); 
      //c.commit();

      //if(rs.getRow() > 0)
          while ( rs.next() ) { //HERE IS THE PROBLEM
                 wi[i].wellID = rs.getInt("ID");
                 i++;
          }

      wi2 = new WellInfo[i];
      for(int j = 0; j < i - 1; j++){
          wi2[j] = wi[j];
      }

      rs.close();
      stmt.close();

      return wi2;
    } catch ( Exception e ) {
      System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      System.exit(0);
    }

    System.out.println("Operation done successfully");
    return wi2;
连接c=null;
语句stmt=null;
WellInfo[]wi=新的WellInfo[60000];
WellInfo[]wi2=新的WellInfo[0];
int i=0;
试一试{
Class.forName(“org.sqlite.JDBC”);
c=DriverManager.getConnection(“jdbc:sqlite:wellec.db”);
//c、 设置自动提交(错误);
System.out.println(“已成功打开数据库”);
stmt=c.createStatement();
结果集rs=stmt.executeQuery(“从WELLINFO中选择*);
//c、 提交();
//如果(rs.getRow()>0)
而(rs.next()){//这就是问题所在
wi[i].wellID=rs.getInt(“ID”);
i++;
}
wi2=新井信息[i];
对于(int j=0;j
很抱歉,没有指定问题。这是:


当我调用rs.next()时,我得到了错误java.lang.NullPointerException。

wi[i]
null
=>您不能调用
wi[i]。在实例化
wi[i]
之前,您应该执行以下操作


wi[i]=new WellInfo()
然后调用
wi[i].wellID

在显示NPEi的哪一行添加了问题行。