you are using an invalid object, did you create an instance using "new"? show your code

解决方案 »

  1.   

    是你试图将一个值赋给不存在的变量
    是不是定义了数组什么的阿你
    而且数组没有定义长度?
    或者对数组进行了copy什么的
      

  2.   

    import java.sql.*;public class  mytest
    {
    public static void main(String[] args) 
    {
    SearchType test = new SearchType();
    System.out.println(test.mnumber);
    for(int i=0;i<test.mnumber;i++)
    System.out.println(test.mtype[i]);
    }
    }
    class SearchType
    {
    String url = "jdbc:odbc:Question";
    String sql;
    String qtype[],mtype[],atype[];
    int qnumber,anumber;
    public SearchType()
    {
    try{
    anumber =  qnumber = 0;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connect = DriverManager.getConnection(url);
    Statement state = connect.createStatement();
    ResultSet rs;
    sql = "SELECT AreaDescription FROM QuestionArea";
    rs = state.executeQuery(sql);
    i = 0;
    while(rs.next()){
    atype[i] = rs.getString(1);
    anumber++;
    i++;
    }
    sql = "SELECT QuestionTypeDescription FROM QuestionType";
    rs = state.executeQuery(sql);
    i = 0;
    while(rs.next()){
    qtype[i] = rs.getString(1);
    qnumber++;
    i++;
    }
    state.close();
    connect.close();
    }
    catch(ClassNotFoundException cnfe){
    System.err.println(cnfe);
    }
    catch(SQLException sqle){
    System.err.println(sqle.getMessage());
    System.err.println(sqle.getSQLState());
    System.err.println(sqle.getErrorCode());
    }
    }
    }
      

  3.   

    import java.sql.*;public class  mytest
    {
    public static void main(String[] args) 
    {
    SearchType test = new SearchType();
    System.out.println(test.mnumber);
    for(int i=0;i<test.mnumber;i++)
    System.out.println(test.mtype[i]);
    }
    }
    class SearchType
    {
    String url = "jdbc:odbc:Question";
    String sql;
    String qtype[],mtype[],atype[];
    int qnumber,anumber;
    public SearchType()
    {
    try{
    anumber =  qnumber = 0;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connect = DriverManager.getConnection(url);
    Statement state = connect.createStatement();
    ResultSet rs;
    sql = "SELECT AreaDescription FROM QuestionArea";
    rs = state.executeQuery(sql);
    i = 0;
    while(rs.next()){
    atype[i] = rs.getString(1);
    anumber++;
    i++;
    }
    sql = "SELECT QuestionTypeDescription FROM QuestionType";
    rs = state.executeQuery(sql);
    i = 0;
    while(rs.next()){
    qtype[i] = rs.getString(1);
    qnumber++;
    i++;
    }
    state.close();
    connect.close();
    }
    catch(ClassNotFoundException cnfe){
    System.err.println(cnfe);
    }
    catch(SQLException sqle){
    System.err.println(sqle.getMessage());
    System.err.println(sqle.getSQLState());
    System.err.println(sqle.getErrorCode());
    }
    }
    }
      

  4.   

    你没有initialize atype[], qtype[] tryatype = new String[1000];
    qtype = new String[1000];before you run the sql query