无法访问SQLite数据库表

uyto3xhc  于 2022-11-14  发布在  SQLite
关注(0)|答案(1)|浏览(175)

我正在从服务器下载SQLite数据库并将其存储在设备上。但是当尝试访问这些表时,它显示错误android.rabase.sqlite.SQLiteException:No That table:Foods(Code 1 SQLITE_Error):,同时编译:SELECT DATE_TIME,Food,Carories from Foods
当尝试使用SQLiteBrowser访问表时,它是可访问的。

public class calorieChart extends AppCompatActivity {

    Integer entries=600;

    @Override
    protected void  onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_otp);
    }

    @Override
    protected void onResume(){   
        super.onResume();
        SharedPreferences 
        sharedPreferences=this.getSharedPreferences("AppPreferences",MODE_PRIVATE);
        String mobile=sharedPreferences.getString("userMobileNumber","") ;
        String filekey=mobile+".db";
        SQLiteDatabase db=SQLiteDatabase.openDatabase("/data/data/com.dieto.nutri/files/"+filekey,null,SQLiteDatabase.OPEN_READWRITE);
        db.execSQL("CREATE TABLE IF NOT EXISTS Foods1 (Date_Time TEXT ,Food Text ,Calories INTEGER);");

        String Cols[]={"Date_Time","Food","Calories"};
        Cursor foods_cursor=db.query("Foods",Cols,null,null,null,null,null);
        ArrayList<String> date_Time=new ArrayList<>();
        ArrayList<String> food_item=new ArrayList<>();
        ArrayList<String> calories=new ArrayList<>();
        int i=0;
        Toast.makeText(calorieChart.this,foods_cursor.getString(1).toString(),Toast.LENGTH_SHORT).show();

        if(foods_cursor.moveToFirst()){
            do{
            date_Time.add(foods_cursor.getString(0));
            calories.add(foods_cursor.getString(2));
            food_item.add(foods_cursor.getString(1));
            i=i+1;
            }while(foods_cursor.moveToNext()&&i<entries);
        }
        foods_cursor.close();
    }
}
String filekey=mobile+".db";
File file;

Amplify.Storage.downloadFile(
    filekey,
    file=new File(getApplicationContext().getFilesDir()+"/"+filekey),
    result->Log.i("Myamplifyapp","File downloaded "+result.getFile().getName()),
    error->Log.i("Myamplifyapp","File download Failed",error)
);

if(!file.exists()){
    try{
        file.createNewFile();
        Toast.makeText(userOtpActivity.this,"File Created",Toast.LENGTH_SHORT).show();
    } catch (Exception e){
        Toast.makeText(userOtpActivity.this,e.toString(),Toast.LENGTH_SHORT).show();
    }
}
3gtaxfhh

3gtaxfhh1#

CREATE语句将表命名为Foods1,而不是后面使用的表名称Foods,因此找不到表Foods

相关问题