执行由sqlite.SQLiteException引起的doInBackground()时出错

时间:2016-11-02 14:29:13

标签: java android android-sqlite sugarorm

我最近不得不参加一个项目并修复崩溃。崩溃发生在doInBackground上,AsyncTask通过调用:

来触发
   public static void getCurrentUser(final UserDBInterface listener) {
        new GetCurrentUserAsyncTask(listener).execute();
    }

调用AsyncTask。

public class GetCurrentUserAsyncTask extends AsyncTask<String, Void, User> {
    private UserDBInterface listener;

    public GetCurrentUserAsyncTask(final UserDBInterface listener) {
        this.listener = listener;
    }

    protected User doInBackground(final String... strings) {
        return DatabaseHelper.getCurrentUser();
    }

    protected void onPostExecute(final User result) {
        listener.onCurrentUserReady(result);
    }
}

GetCurrentUser方法:

public static User getCurrentUser() {
    final TotemSharedPreferences totemSharedPreferences = new TotemSharedPreferences();
    final List<User> users = Select.from(User.class).where(DatabaseHelper.REMOTE_ID_LABEL + " = " + totemSharedPreferences.getUserId()).list();
    if (!users.isEmpty()) {
        final User mUser = users.get(0);
        mUser.setUserBadge(DatabaseHelper.getAllUserBadges(mUser.getUserId()));
        mUser.setKudosReceived(DatabaseHelper.getAllUserReceivedKudos(mUser.getUserId()));
        mUser.setTeam(DatabaseHelper.getTeam(mUser.getTeamId()));
        mUser.setCompany(DatabaseHelper.getCompany());
        mUser.setStartedOn(new DateTime(mUser.getStartedOnString()));
        mUser.setUserTeams(getAllUserTeams(mUser.getUserId()));

        for (final UserTeam mUserTeam : mUser.getUserTeams())
            if (mUserTeam.getRemoteId() == mUser.getActiveUserTeamId())
                mUser.setKudosFund(mUserTeam.getKudosFund());

        return mUser;
    } else
        return totemSharedPreferences.getUser();
}

用户类:

public class User extends SugarRecord {

    @Column(name = "username")
    @Expose
    @SerializedName("username")
    String mUsername;

    @Column(name = "position")
    @Expose
    @SerializedName("position")
    String mPosition;

    @Column(name = "image_url")
    @Expose
    @SerializedName("image_url")
    String mImageUrl;

    @Column(name = "name")
    @Expose
    @SerializedName("name")
    String mName;

    @Ignore
    String mPassword;

    @Column(name = "remote_id", unique = true)
    @Expose
    @SerializedName("id")
    int mUserId;

    @Ignore
    @Expose
    @SerializedName("started_on")
    DateTime mStartedOn;

    @Column(name = "started_on")
    private String startedOnString;

    @Column(name = "company")
    @Expose
    @SerializedName("company")
    Company mCompany;

    @Column(name = "company_id")
    @Expose
    @SerializedName("company_id")
    int mCompanyId;

    @Column(name = "profile_id")
    @Expose
    @SerializedName("profile_id")
    int mProfileId;

    @Column(name = "team_id")
    @Expose
    @SerializedName("team_id")
    int mTeamId;

    @Column(name = "approved")
    @Expose
    @SerializedName("approved")
    boolean mApproved;

    @Column(name = "disabled")
    @Expose
    @SerializedName("disabled")
    boolean mDisabled;

    @Ignore
    @Expose
    @SerializedName("team")
    Team mTeam;

    @Ignore
    @Expose
    @SerializedName("user_teams")
    List<UserTeam> mUserTeams;

    @Column(name = "kudos_fund")
    @Expose
    @SerializedName("kudos_fund")
    int mKudosFund;

    @Ignore
    @Expose
    @SerializedName("kudos_received")
    List<Kudos> mKudosReceived;

    @Ignore
    @Expose
    @SerializedName("badges")
    List<UserBadge> mUserBadge;

    @Column(name = "active_user_team_id")
    @Expose
    @SerializedName("active_user_team_id")
    int mActiveUserTeamId;

    @Column(name = "kudos_received_total")
    @Expose
    @SerializedName("kudos_received_total")
    int mKudosReceivedTotal;

    public User() {

    }

    @Override
    public long save() {
        if (mStartedOn != null)
            startedOnString = mStartedOn.toString();

        if (mUserTeams != null)
            for (final UserTeam mUserTeam : mUserTeams)
                if (mUserTeam.getRemoteId() == mActiveUserTeamId)
                    mKudosFund = mUserTeam.getKudosFund();
        return super.save();
    }

    public String getStartedOnString() {
        return startedOnString;
    }

}

我实际上刚开始进行android开发 - 我是一名iOS开发人员而且不习惯AsyncTasks。有人知道问题的根本原因吗?这些是我拥有的唯一日志:

#0. Crashed: AsyncTask #1: 0 0 0x0000000000000000
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

--

Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
Caused by android.database.sqlite.SQLiteException: duplicate column name: users_count (code 1): , while compiling: alter table USER_TEAM add users_count INTEGER;
       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
       at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1093)
       at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:670)
       at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
       at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
       at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
       at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1798)
       at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1729)
       at com.orm.SchemaGenerator.executeScript(SchemaGenerator.java:97)
       at com.orm.SchemaGenerator.executeSugarUpgrade(SchemaGenerator.java:75)
       at com.orm.SchemaGenerator.doUpgrade(SchemaGenerator.java:52)
       at com.orm.SugarDb.onUpgrade(SugarDb.java:31)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
       at com.orm.SugarDb.getDB(SugarDb.java:36)
       at com.orm.SugarRecord.find(SugarRecord.java:189)
       at com.orm.query.Select.list(Select.java:118)
       at com.playconsulting.totem.database.DatabaseHelper.getCurrentUser(DatabaseHelper.java:965)
       at com.playconsulting.totem.database.asynctasks.GetCurrentUserAsyncTask.doInBackground(GetCurrentUserAsyncTask.java:21)
       at com.playconsulting.totem.database.asynctasks.GetCurrentUserAsyncTask.doInBackground(GetCurrentUserAsyncTask.java:13)
       at android.os.AsyncTask$2.call(AsyncTask.java:288)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#0. Crashed: AsyncTask #1: 0 0 0x0000000000000000
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#1. MarketingHandler
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:143)
       at android.os.Looper.loop(Looper.java:130)
       at android.os.HandlerThread.run(HandlerThread.java:61)

#2. ProfileHandler
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:143)
       at android.os.Looper.loop(Looper.java:130)
       at android.os.HandlerThread.run(HandlerThread.java:61)

#3. OkHttp https://api.totem.team/api/client/user
       at org.joda.time.convert.StringConverter.<clinit>(StringConverter.java:44)
       at org.joda.time.convert.ConverterManager.<init>(ConverterManager.java:107)
       at org.joda.time.convert.ConverterManager.getInstance(ConverterManager.java:90)
       at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:171)
       at org.joda.time.DateTime.<init>(DateTime.java:257)
       at com.playconsulting.totem.rest.deserializers.DateTimeDeserializer.deserialize(DateTimeDeserializer.java:18)
       at com.playconsulting.totem.rest.deserializers.DateTimeDeserializer.deserialize(DateTimeDeserializer.java:15)
       at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:117)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:217)
       at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
       at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
       at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:117)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:217)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:117)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:217)
       at com.google.gson.Gson.fromJson(Gson.java:861)
       at com.google.gson.Gson.fromJson(Gson.java:826)
       at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:36)
       at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:24)
       at retrofit.OkHttpCall.parseResponse(OkHttpCall.java:148)
       at retrofit.OkHttpCall.access$100(OkHttpCall.java:29)
       at retrofit.OkHttpCall$1.onResponse(OkHttpCall.java:94)
       at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
       at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#4. AsyncTask #3
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#5. DB_Thread
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:143)
       at android.os.Looper.loop(Looper.java:130)
       at android.os.HandlerThread.run(HandlerThread.java:61)

#6. HeapTrimmerDaemon
       at dalvik.system.VMRuntime.trimHeap(VMRuntime.java)
       at java.lang.Daemons$HeapTrimmerDaemon.run(Daemons.java:312)
       at java.lang.Thread.run(Thread.java:818)

#7. ReferenceQueueDaemon
       at java.lang.Object.wait(Object.java)
       at java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:133)
       at java.lang.Thread.run(Thread.java:818)

#8. Queue
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:510)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.performOperation(DependencyPriorityBlockingQueue.java:197)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.get(DependencyPriorityBlockingQueue.java:236)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:65)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:46)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#9. ManifestHandler
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:143)
       at android.os.Looper.loop(Looper.java:130)
       at android.os.HandlerThread.run(HandlerThread.java:61)

#10. main
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:143)
       at android.os.Looper.loop(Looper.java:130)
       at android.app.ActivityThread.main(ActivityThread.java:5951)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

#11. Queue
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:510)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.performOperation(DependencyPriorityBlockingQueue.java:197)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.get(DependencyPriorityBlockingQueue.java:236)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:65)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:46)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#12. Queue
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:510)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.performOperation(DependencyPriorityBlockingQueue.java:197)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.get(DependencyPriorityBlockingQueue.java:236)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:65)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:46)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#13. AsyncTask #1
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:400)
       at java.util.concurrent.FutureTask.get(FutureTask.java:162)
       at com.crashlytics.android.core.CrashlyticsExecutorServiceWrapper.executeSyncLoggingException(CrashlyticsExecutorServiceWrapper.java:47)
       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:235)
       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

#14. Crashlytics Report Uploader
       at java.lang.Thread.sleep(Thread.java)
       at java.lang.Thread.sleep(Thread.java:1031)
       at java.lang.Thread.sleep(Thread.java:985)
       at com.crashlytics.android.core.ReportUploader$Worker.attemptUploadWithRetry(ReportUploader.java:146)
       at com.crashlytics.android.core.ReportUploader$Worker.onRun(ReportUploader.java:131)
       at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30)
       at java.lang.Thread.run(Thread.java:818)

#15. Queue
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:510)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.performOperation(DependencyPriorityBlockingQueue.java:197)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.get(DependencyPriorityBlockingQueue.java:236)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:65)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:46)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#16. OkHttp ConnectionPool
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:197)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2055)
       at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:435)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#17. AsyncTask #2
       at dalvik.system.DexFile.getClassNameList(DexFile.java)
       at dalvik.system.DexFile.access$100(DexFile.java:36)
       at dalvik.system.DexFile$DFEnum.<init>(DexFile.java:258)
       at dalvik.system.DexFile.entries(DexFile.java:246)
       at com.orm.util.ReflectionUtil.getAllClasses(ReflectionUtil.java:297)
       at com.orm.util.ReflectionUtil.getDomainClasses(ReflectionUtil.java:253)
       at com.orm.SchemaGenerator.doUpgrade(SchemaGenerator.java:44)
       at com.orm.SugarDb.onUpgrade(SugarDb.java:31)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
       at com.orm.SugarDb.getDB(SugarDb.java:36)
       at com.orm.SugarRecord.find(SugarRecord.java:189)
       at com.orm.query.Select.list(Select.java:118)
       at com.playconsulting.totem.database.DatabaseHelper.getCurrentUser(DatabaseHelper.java:965)
       at com.playconsulting.totem.database.asynctasks.GetCurrentUserAsyncTask.doInBackground(GetCurrentUserAsyncTask.java:21)
       at com.playconsulting.totem.database.asynctasks.GetCurrentUserAsyncTask.doInBackground(GetCurrentUserAsyncTask.java:13)
       at android.os.AsyncTask$2.call(AsyncTask.java:288)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#18. FinalizerWatchdogDaemon
       at java.lang.Thread.sleep(Thread.java)
       at java.lang.Thread.sleep(Thread.java:1031)
       at java.lang.Thread.sleep(Thread.java:985)
       at java.lang.Daemons$FinalizerWatchdogDaemon.sleepFor(Daemons.java:257)
       at java.lang.Daemons$FinalizerWatchdogDaemon.waitForFinalization(Daemons.java:268)
       at java.lang.Daemons$FinalizerWatchdogDaemon.run(Daemons.java:216)
       at java.lang.Thread.run(Thread.java:818)

#19. AnalyticsHandler
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:143)
       at android.os.Looper.loop(Looper.java:130)
       at android.os.HandlerThread.run(HandlerThread.java:61)

#20. FinalizerDaemon
       at java.lang.Object.wait(Object.java)
       at java.lang.Object.wait(Object.java:422)
       at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:101)
       at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:72)
       at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:173)
       at java.lang.Thread.run(Thread.java:818)

#21. Queue
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:510)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.performOperation(DependencyPriorityBlockingQueue.java:197)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.get(DependencyPriorityBlockingQueue.java:236)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:65)
       at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:46)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

#22. pool-5-thread-1
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor(Thread.java:1220)
       at sun.misc.Unsafe.park(Unsafe.java:299)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
       at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1097)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

目前在版本19 Manifest

  <meta-data
        android:name="VERSION"
        android:value="19" />
    <meta-data

然而重复的行在15

2 个答案:

答案 0 :(得分:1)

我知道我被投了很多,但基本上答案是Sugar DB会自动向Databse添加列并且文档错误。更改表时无需执行迁移。我从2.sql,3.sql等中删除了SQL,只是将它们留空了。如果你必须更改列的名称等,只在那里插入东西。

答案 1 :(得分:0)

这可能是因为&#34; onUpgrade&#34;调用倍数倍。所以你需要检查以下内容。

  1. 提供适当的数据库版本并传递给DatabaseHelper构造函数

    public DatabaseHelper(Context aContext) {
        super(aContext, databaseName, null, databaseVersion);
    }
    
  2. 在onUpgrade中检查正确的代码。

    public void onUpgrade(SQLiteDatabase db, int oldVersion , int newVersion) {
        if (oldVersion != DATABASE_VERSION) {
            updateTablesUSERTEAM(db);
        }
    }
    
  3. 转到设置 - &gt;应用 - &gt;找到你的申请 - &gt;明确数据

  4. 重新运行您的代码。