我正在研究这个项目,如果应用程序处于离线状态,数据将被保存到SQLite。但是当我构建和运行时,我得到这个错误。我也重新检查了SQL查询。但无法得到确切的问题是什么。
主要活动.java
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
EditText name;
RecyclerView.LayoutManager layoutManager;
RecyclerAdapter recyclerAdapter;
ArrayList<Contact> arrayList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.recyclerView);
name=findViewById(R.id.name);
layoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
recyclerAdapter=new RecyclerAdapter(arrayList);
recyclerView.setAdapter(recyclerAdapter);
readfromlite();
}
private void readfromlite()
{
arrayList.clear();
DbHelper dbHelper=new DbHelper(this);
SQLiteDatabase database=dbHelper.getReadableDatabase();
Cursor cursor=dbHelper.readlite(database);
while (cursor.moveToNext())
{
String name=cursor.getString(cursor.getColumnIndex(DbContract.NAME));
int sync_status= cursor.getInt(cursor.getColumnIndex(DbContract.sync_status));
arrayList.add(new Contact(name,sync_status));
}
recyclerAdapter.notifyDataSetChanged();
cursor.close();
dbHelper.close();
}
DBHelper.java
public class DbHelper extends SQLiteOpenHelper {
private static final int dbversion=1;
private static final String ctable= " create TABLE if not EXISTS " + DbContract.tname + " (id integer primary key autoincrement, " + DbContract.NAME + " text , " + DbContract.sync_status + " integer ) ; " ;
private static final String dtable= " drop table if EXISTS " + DbContract.tname ;
手掌心
ITMISS
POPMUISE
相关分类