I am making an android app that involves an internal database. I decided to open the database file rather than produce it within the app.
this is the code:
private static String databasePath = "H:\Workspace\PetrocVLE\assets";
public SQLiteDatabase db = SQLiteDatabase.openDatabase(databasePath, null, 0);
this is the error that is being given:
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
I thought this might mean that there are symbols within the databasePath variable which are not allowed within a string variable, however I have seen other String variables that used these within java.
Can anybody tell me what I am doing wrong? thankyou
\\
is a special character used in Java Strings
, you would need to escape it,
private static String databasePath = "H:\\Workspace\\PetrocVLE\\assets";
However, file paths on Android normally take this format
private static String databasePath = "/Workspace/PetrocVLE/assets";
使用/
代替,因为它与操作系统无关:
private static String databasePath = "H:/Workspace/PetrocVLE/assets";
您可能还希望独立于驱动器,并引用代表您的驱动器号的变量或尝试使用相对路径 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.