在我们的项目中,我们使用数据模型来存储从服务接收的数据.因此,在我们将数据插入数据库的特定情况下,我们使用objModelClass.getClass().getDeclaredFields()方法来获取所有字段名称,并且它正确地返回该类的所有字段名称,但也返回一个带有名称的额外字段"$ change",在课堂上不存在.
奇怪的是,在Android工作室中没有这样的问题但是当我们升级到android studio 2.0时就发生了这种情况.
虽然我已经应用了快速修复,但我需要正确解决这个问题.我想知道它为什么会发生?
这个函数使用这个方法
public void insertValuesIntoTable(final String strTableName, ArrayList<Object> alObjClasses,
String strPrimaryKey, String strCompositeKey) {
try {
SQLiteDatabase db_w = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
//Iterate through every model class Object in the ArrayList and transfer the contents to the DB
if (alObjClasses != null)
for (Object objModelClass : alObjClasses) {
for (Field field : objModelClass.getClass().getDeclaredFields()) {
//Encrypt value if encryption is enabled & the column is to be encrypted
try {
field.setAccessible(true); …Run Code Online (Sandbox Code Playgroud)