- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我使用助手复制数据库没问题。但是由于今天重新格式化了我的电脑并安装了 eclipse,所以我不能再复制数据库了。可能是模拟器的 sd 卡导致的问题。这是原木猫说的。
07-23 14:23:48.875: E/AndroidRuntime(237): Uncaught handler: thread main exiting due to uncaught exception
07-23 14:23:48.885: E/AndroidRuntime(237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frux.kfcmobile/com.frux.kfcmobile.KFCmobileActivity}: android.database.sqlite.SQLiteException: no such table: first: , while compiling: SELECT *from first
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.os.Looper.loop(Looper.java:123)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-23 14:23:48.885: E/AndroidRuntime(237): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 14:23:48.885: E/AndroidRuntime(237): at java.lang.reflect.Method.invoke(Method.java:521)
07-23 14:23:48.885: E/AndroidRuntime(237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-23 14:23:48.885: E/AndroidRuntime(237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-23 14:23:48.885: E/AndroidRuntime(237): at dalvik.system.NativeStart.main(Native Method)
07-23 14:23:48.885: E/AndroidRuntime(237): Caused by: android.database.sqlite.SQLiteException: no such table: first: , while compiling: SELECT *from first
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:59)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:49)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1220)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1193)
07-23 14:23:48.885: E/AndroidRuntime(237): at com.frux.kfcmobile.KFCmobileActivity.onCreate(KFCmobileActivity.java:42)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-23 14:23:48.885: E/AndroidRuntime(237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
这是我的 DBHelper
公共(public)类 DatabaseHelper 扩展了 SQLiteOpenHelper{
private static String DB_PATH = "/data/data/com.frux.kfcmobile/databases/";
private static String DB_NAME = "database";
private SQLiteDatabase myDataBase;
private final Context myContext;
private static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
// TODO Auto-generated constructor stub
super(context, DB_NAME, null, DATABASE_VERSION);
this.myContext = context;
}
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
this.getWritableDatabase();
this.close();
}else{
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
this.close();
try {
copyDataBase();
} catch (IOException e) {
//throw new Error("Error copying database message");
}
}
}
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
//Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
@Override
public synchronized void close() {
if(myDataBase != null)
myDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
最佳答案
关注下一行,不要忘记添加 .sqlite
扩展名:
private static String DB_NAME = "wfbos.sqlite";
它对我有用。
关于android - 复制数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11607468/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!