我已经面对这个错误几天了,我不知道问题可能是什么。这是我的logcat。
FATAL EXCEPTION: main
Process: com.example.sonnie.mytwende, PID: 5848
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getReadableDatabase(SQLiteAssetHelper.java:264)
at com.example.sonnie.mytwende.Database.addToBookings(Database.java:52)
at com.example.sonnie.mytwende.CarDetailsFragment$1.onClick(CarDetailsFragment.java:94)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
我已将资产/数据库文件夹中的SQLite数据库导入,但我的数据库中也出现此错误,我不知道是否存在问题。
File was loaded in the wrong encoding:'UTF-8'
的AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
我应该点击FAB然后将汽车添加到数据库中作为订单。
CarDetails.java
btnBook=(FloatingActionButton) v.findViewById(R.id.btnBook);
btnBook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Database(getContext()).addToBookings(new Order(
carid,
currentCar.getName(),
currentCar.getPricePerDay()
));
StyleableToast st31= new StyleableToast(getActivity(),"Added to your bookings",Toast.LENGTH_LONG);
st31.setBackgroundColor(Color.parseColor("#71DA98"));
st31.setTextColor(Color.BLACK);
st31.setIcon(R.drawable.success);
}
});
CartFragment.java
public class CartFragment extends Fragment {
TextView totalprice;
FButton btnPlaceOrder;
RecyclerView listBookings;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference request;
List<Order> cart=new ArrayList<>();
CartAdapter adapter;
public CartFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.fragment_cart, container, false);
database=FirebaseDatabase.getInstance();
request=database.getReference("Requests");
listBookings=(RecyclerView) v.findViewById(R.id.listBookings);
listBookings.setHasFixedSize(true);
layoutManager=new LinearLayoutManager(getContext());
listBookings.setLayoutManager(layoutManager);
totalprice=(TextView) v.findViewById(R.id.totalprice);
btnPlaceOrder=(FButton) v.findViewById(R.id.btnPlaceOrder);
List<Order> cart=new ArrayList<>();
loadListCars();
return v;
}
private void loadListCars() {
cart=new Database(getContext()).getBoookings();
adapter=new CartAdapter(cart,getContext());
listBookings.setAdapter(adapter);
int total=0;
for(Order order:cart)
total+=(Integer.parseInt(order.getCar_STPrice()))*(Integer.parseInt(order.getDays()));
Locale locale=new Locale("en", "Ksh");
NumberFormat fmat=NumberFormat.getCurrencyInstance(locale);
totalprice.setText(fmat.format(total));
}
}
CartAdapter.java
class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView cart_item_name,cart_item_price;
public ImageView cart_item_count;
private ItemClickListener itemClickListener;
public void setCart_item_name(TextView cart_item_name) {
this.cart_item_name = cart_item_name;
}
public CartViewHolder(View itemView) {
super(itemView);
cart_item_name=(TextView) itemView.findViewById(R.id.cart_item_name);
cart_item_price=(TextView) itemView.findViewById(R.id.cart_item_price);
cart_item_count=(ImageView) itemView.findViewById(R.id.cart_item_count);
}
@Override
public void onClick(View v) {
}
}
public class CartAdapter extends RecyclerView.Adapter<CartViewHolder>{
private List<Order> listData=new ArrayList<>();
private Context context;
public CartAdapter(List<Order> listData, Context context) {
this.listData = listData;
this.context = context;
}
@Override
public CartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater=LayoutInflater.from(context);
View itemView=inflater.inflate(R.layout.cart_layout,parent,false);
return new CartViewHolder(itemView);
}
@Override
public void onBindViewHolder(CartViewHolder holder, int position) {
Locale locale=new Locale("en", "Ksh");
NumberFormat fmat=NumberFormat.getCurrencyInstance(locale);
int price=(Integer.parseInt(listData.get(position).getCar_STPrice()));
holder.cart_item_price.setText(fmat.format(price));
holder.cart_item_name.setText(listData.get(position).getCar_Name());
}
@Override
public int getItemCount() {
return listData.size();
}
}