亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: JAVA顯示空指針,請(qǐng)問(wèn)哪里出問(wèn)題了? [打印本頁(yè)]

作者: Wheat_southwest    時(shí)間: 2014-06-02 22:42
標(biāo)題: JAVA顯示空指針,請(qǐng)問(wèn)哪里出問(wèn)題了?
本帖最后由 Wheat_southwest 于 2014-06-03 07:35 編輯

public class dbhelper extends SQLiteOpenHelper{
    private static final String DB_NAME = "school_activity.db";
    private static final int DB_VERSION = 1;
    private static final String TABLE_NAME1 = "lecture";
    private static final String TABLE_NAME2 = "stu";
    private static final String TABLE_NAME3 = "com";
    private static final String CREATE_INFO1 = "create table if not exists lecture("
            + "_id integer primary key autoincrement,name varchar(20),"
            + "time varchar(20),place varchar(20),hostname varchar(20),"
            +"more varchar(50),contact varchar(20)";
    private static final String CREATE_INFO2 = "create table if not exists stu("
            + "_id integer primary key autoincrement,name varchar(20),"
            + "time varchar(20),place varchar(20),hostname varchar(20),"
            +"more varchar(50),contact varchar(20)";
    private static final String CREATE_INFO3 = "create table if not exists com("
            + "_id integer primary key autoincrement,name varchar(20),"
            + "time varchar(20),place varchar(20),hostname varchar(20),"
            +"more varchar(50),contact varchar(20)";
    private SQLiteDatabase db;
     dbhelper(Context context){
      super(context,DB_NAME,null,DB_VERSION);
}
@Override
    public void onCreate(SQLiteDatabase db){
     this.db=db;
     db.execSQL(CREATE_INFO1);
     Log.i("TABLE1","created successfully!");
     db.execSQL(CREATE_INFO2);
     Log.i("TABLE2","created successfully!");
     db.execSQL(CREATE_INFO3);
     Log.i("TABLE3","created successfully!");
}
    public void insert(SQLiteDatabase MDB, String tableName) {
       ContentValues values=new ContentValues();
        values.put("name","信管");
        values.put("time","2014.6.1");
        values.put("place","204");
        values.put("hostname","名字");
        values.put("more","關(guān)于安卓編程");
        values.put("contact","名字  手機(jī)");
        MDB.insert(tableName,null,values);
    }
    public Cursor query(String tableName) {
        db = getWritableDatabase();
        Cursor c = db.query(tableName, null, null, null, null, null, null);
        return c;
    }

    // Return cursor by SQL string
    public Cursor rawQuery(String sql, String[] args) {
        db = getWritableDatabase();
        Cursor c = db.rawQuery(sql, args);
        return c;
    }
    public void execSQL(String sql) {
        db = getWritableDatabase();
        db.execSQL(sql);
    }
    public void del(int id,String tableName) {
        if (db == null)
            db = getWritableDatabase();
        db.delete(tableName, "id=?", new String[] { String.valueOf(id) });
    }
    public void close() {
        if (db != null)
            db.close();
    }
    public void onUpgrade(SQLiteDatabase db,int oldversion,int newversion){

    }

}

















public class activities extends Activity {
    SQLiteDatabase db=null;
    dbhelper dbhelper;
    ArrayList<HashMap<String,Object>> listdata;
    SimpleAdapter listItemAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ecnu_type);
        dbhelper=new dbhelper(activities.this);
        dbhelper.onCreate(db);
        dbhelper.insert(db,"lecture");
        Cursor cursor=dbhelper.rawQuery("select name,hostname from lecture",null);
        listdata=new ArrayList<HashMap<String, Object>>();
     //   cursor.moveToFirst();
        int columnsize=cursor.getColumnCount();
        while(cursor.moveToNext()){

            HashMap<String,Object> map=new HashMap<String, Object>();
            for(int i=0;i<columnsize;i++){
                map.put("name", cursor.getString(1));
                map.put("hostname",cursor.getString(4));

            }
            listdata.add(map);
        }
        ListView list=(ListView)findViewById(R.id.activity_items);
        listItemAdapter=new SimpleAdapter(activities.this,listdata,R.layout.item,new String[]{"name","hostname"},
                new int[]{R.id.name,R.id.hostname});
        list.setAdapter(listItemAdapter);


        }

}

作者: Wheat_southwest    時(shí)間: 2014-06-02 22:46
這是運(yùn)行后的結(jié)果







歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2