问题描述
通常我想要做的是访问位于 assets/app.db 的现有数据库
我很确定我发现原因就在这段代码中import java.util.Scanner;
public class PaintCostCalculator {
public static void main( String args[] )
{
try (Scanner input = new Scanner(system.in)) {
//variable declarations
int NoOfRooms;
int RoomCounter;
int choice;
int Area = 0;
int AreaSum = 0;
int TotalLSCost;
int TotalSGCost;
int TotalMatCost;
//constants declarations
final int PaintCoverage = 16;
final int LowSheenCost = 17.6;
final int SemiGlossCost = 20;
final int MatteCost = 14.3;
//code
System.out.print("Please enter the number of rooms to be painted: ");
NoOfRooms = input.nextInt();
for(RoomCounter = 0; RoomCounter < NoOfRooms; RoomCounter ++) {
System.out.printf("\nEnter the area of room %d in m^2.: ",RoomCounter + 1);
Area = input.nextInt();
AreaSum = AreaSum + Area;
}
System.out.println("\nPlease choose one of the following paint options: \n1. Low Sheen($17.60/L)\n2. Semi Gloss($20/L)\n3. Matte($14.30/L)");
choice = input.nextInt();
switch (choice)
{
case 1:
System.out.print("You have chosen Low Sheen\n");
TotalLSCost = (AreaSum / PaintCoverage) * LowSheenCost;
System.out.printf("To paint a total area of %dm^2 with Low Sheen paint it would cost a total of %d",AreaSum,TotalLSCost);
break;
case 2:
System.out.print("You have chosen Semi Gloss\n");
TotalSGCost = (AreaSum / PaintCoverage) * SemiGlossCost;
System.out.printf("To paint a total area of %dm^2 with Semi Gloss paint it would cost a total of %d",TotalSGCost);
break;
case 3:
System.out.print("You have chosen Matte\n");
TotalMatCost = (AreaSum / PaintCoverage) * MatteCost;
System.out.printf("To paint a total area of %dm^2 with Matte paint it would cost a total of %d",TotalMatCost);
break;
}
}
}
}
这是我的功能不起作用:
data = await rootBundle.load("assets/app.db");
我检查了以下内容:
- 它会删除任何现有的数据库
-
Future<Database> openDB() async{ var dbDir = await getDatabasesPath(); var dbPath = join(dbDir,"Flutter.db"); // Delete any existing database: await deleteDatabase(dbPath); // Create the writable database file from the bundled demo database file: var data; data = await rootBundle.load("assets/app.db"); List<int> bytes = data.buffer.asUint8List(data.offsetInBytes,data.lengthInBytes); await File(dbPath).writeAsBytes(bytes); var db = await openDatabase(dbPath); return db; }
在data
之前为空 - 在我手动更新数据库并重新加载代码后,
rootBundle.load
的值保持不变 - 数据库存在于
data
之后
既然一切正常,我得出的结论是错误必须发生在 await File()
你同意还是我错过了什么?我该怎么做才能让它发挥作用?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)