应用在启动时意外崩溃

时间:2018-07-12 11:20:24

标签: android sqlite

我试图将值插入sqlite数据库,但是每当我添加新的insert column命令时,应用程序就会崩溃。

public class EventsDAO implements DAO<Event> {

    private static final String INSERT = "insert into "
            + EventsTable.TABLE_NAME + "(" + EventsColumns._ID + ", "
            + EventsColumns.CHILDNAME +  ", " + EventsColumns.INFO + ", "
            + EventsColumns.PERIOD + ", " + EventsColumns.PERIOD_UNIT + ", "
            + EventsColumns.START_TIME + ") values (?, ?, ?, ?, ?, ?)";




public long insert(Event event) {
        insertStatement.clearBindings();
        insertStatement.bindNull(1);
        insertStatement.bindString(2, event.getChildname());
        insertStatement.bindString(3, event.getAddress());
        insertStatement.bindLong(4, event.getPeriod().getQuantity());
        insertStatement.bindString(5, event.getPeriod().getUnit());
        insertStatement.bindString(6, Utils.dateToString(event.getStartTime()));

        return insertStatement.executeInsert();
    }

我正在尝试为联系人添加新列。这些列已在数据库中成功创建。 我也尝试了LOGCAT,但是我以这个结尾:

  

致命异常:线程11                                                                            程序:,PID:10634                                                                            java.lang.InternalError:运行时关闭期间启动线程                                                                                在java.lang.Thread.nativeCreate(本地方法)                                                                                在java.lang.Thread.start(Thread.java:730)                                                                                在   org.apache.http.impl.conn.tsccm.AbstractConnPool.enableConnectionGC(AbstractConnPool.java:145)                                                                                在   org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.createConnectionPool(ThreadSafeClientConnManager.java:125)                                                                                在   org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager。(ThreadSafeClientConnManager.java:103)                                                                                在org.acra.util.HttpRequest.getHttpClient(HttpRequest.java:214)                                                                                在org.acra.util.HttpRequest.send(HttpRequest.java:141)                                                                                在org.acra.sender.HttpSender.send(HttpSender.java:225)                                                                                在org.acra.SendWorker.sendCrashReport(SendWorker.java:179)                                                                                在org.acra.SendWorker.checkAndSendReports(SendWorker.java:141)                                                                                在org.acra.SendWorker.run(SendWorker.java:77)

1 个答案:

答案 0 :(得分:1)

  

我通过遵循这些方法解决了我的应用在启动时崩溃的问题。


  

我正在使用的数据库是sqlite。

  •   

    通过将应用程序创建的数据库导出到内部存储来检查它。

就我而言,这些是表格列

public static void onCreate(SQLiteDatabase db) {
        StringBuilder sb = new StringBuilder();
        sb.append("CREATE TABLE " + EventsTable.TABLE_NAME + " (");
        sb.append(BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ");
        sb.append(EventsColumns.CHILDNAME + " TEXT, ");
        sb.append(EventsColumns.FNAME + " TEXT, " );
        sb.append(EventsColumns.DOB + " TEXT, ");
        sb.append(EventsColumns.GENDER + " TEXT, ");
        sb.append(EventsColumns.ADDRESS + " TEXT, ");
        sb.append(EventsColumns.CONTACT + " TEXT, ");
        sb.append(EventsColumns.INJECTIONNO + " TEXT, ");
        sb.append(EventsColumns.PERIOD + " INTEGER, ");
        sb.append(EventsColumns.PERIOD_UNIT + " TEXT, ");
        sb.append(EventsColumns.START_TIME + " TEXT");
        sb.append(");");
        db.execSQL(sb.toString());
    }
  

当我使用此命令导出创建的数据库时:

File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd.canWrite()) {
                String currentDBPath = "//data//"+"com.pacakagename"+"//databases//"+databaseName+"";
                String backupDBPath = "backupname.db";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);

                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                }

当我在Datagrip中打开sqlite数据库时,我发现我试图存储其值<address>名称的列的原因由于空间问题发生了变化。

The column i was expecting

  

数据库中创建的列是

The column name that was created

  

地址列末尾有“ TEXT”标签

     

在哪个插入值上解决该应用程序崩溃并Logcat   无法解释为什么会这样。

  • 当我在Try()上使用insert query方法时,在Logcat中显示了异常

希望这篇文章有帮助。