亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我不能在我創建的內部類中使用外部類中的數據

我不能在我創建的內部類中使用外部類中的數據

瀟瀟雨雨 2021-11-03 09:59:48
如您所見,我想創建一個外部類作為我的活動和我的數據庫之間的適配器,以使其更安全 nut 它只是拒絕使用來自內部類的值,我試圖導入這些值但它導入它們沒有意義,我試圖隱藏它們你能解決這個問題還是給我另一種方法來讓我的代碼工作public class DataBaseConnection {    DataBase DataBase;    public DataBaseConnection(Context context)    {         DataBase = new DataBase(context);          public void  dataInsert (String classnumber , String studentsnumber) {         SQLiteDatabase sqLiteDatabase = dataBase.getWritableDatabase();            ContentValues contentValues = new ContentValues();            contentValues.put(DataBase.classname);            contentValues.put(DataBase.studentsnumber);        }    }    class DataBase  extends SQLiteOpenHelper {        private static final String database_name = "DB";        private static final int database_vesion =1;        private static final String UID = "id";        private static final String name = "Name";        private static final String work_mark = "Works Mark";        private static final String test_mark = "Tests mark";        private static final String tableName = "Students";        private static final String classname = "Class name";        private static final String studentsnumber = "Students number";        private Context context;        private static final String tablename1 = "Class";        private static final String CREATE_TABLE1 = "CREATE TABLE " +tablename1+" " +                " ("+UID+" INTEGER PRIMARY KEY AUTOINCREMENT," +                " "+classname+" TEXT VARCHAR(255))," +                " "+studentsnumber+" INTEGER ;";        }
查看完整描述

1 回答

?
SMILET

TA貢獻1796條經驗 獲得超4個贊

您有幾個問題,您在函數中放置了一個函數,這是無效的語法 - 它與類變量可見性無關。也不確定這種方法如何更安全,因為您的數據庫變量是包范圍的。要解決您的直接問題,您需要這樣的東西:


public class DataBaseConnection {


    private final DataBase dataBase;


    public DataBaseConnection(Context context)    {

        dataBase = new DataBase(context);

    }


    public void dataInsert (String classnumber , String studentsnumber) {

        SQLiteDatabase sqLiteDatabase = dataBase.getWritableDatabase();

        ContentValues contentValues = new ContentValues();

        contentValues.put(DataBase.classname, classnumber);

        contentValues.put(DataBase.studentsnumber, studentsnumber);

        sqLiteDatabase.insert( // insert here  )

    }


.. Rest of class


}


查看完整回答
反對 回復 2021-11-03
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號