会议室资料库-初始化光标错误?

时间:2018-10-21 17:21:35

标签: android dagger-2 android-room

我在应用程序中使用会议室数据库。 Android模拟器和我的用户设备中的%99都没有问题,但是我的一些用户遇到了该错误。

java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

完全错误

android.database.CursorWindow.nativeGetString (CursorWindow.java)
android.database.AbstractWindowedCursor.getString (AbstractWindowedCursor.java:66)
me.ibrahimsn.applock.data.local.app.AppDao_Impl.getAllApps (AppDao_Impl.java:202)
me.ibrahimsn.applock.data.local.app.AppRepository.getAll (AppRepository.java:20)
me.ibrahimsn.applock.ui.start.StartViewModel.updateApps (StartViewModel.java:51)
me.ibrahimsn.applock.ui.start.StartActivity.onCreate (StartActivity.java:48)

我正在Dagger 2中使用它,这是我的课程

@Database(entities = {App.class}, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {

    private static AppDatabase INSTANCE;

    public abstract AppDao appDao();

    public static AppDatabase getAppDatabase(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "mydb")
                    .allowMainThreadQueries().build();
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }
}

匕首模块

@Module
public class ApplicationModule {

    @Provides
    @Singleton
    AppDatabase provideRoomDatabase(Context context) {
        return AppDatabase.getAppDatabase(context);
    }

    @Provides
    @Singleton
    AppDao provideAppDao(AppDatabase appDatabase) {
        return appDatabase.appDao();
    }
}

@Dao
public interface AppDao {

    @Query("SELECT * FROM app")
    List<App> getAllApps();

    @Query("SELECT * FROM app WHERE label LIKE :query ORDER BY status DESC")
    List<App> findApps(String query);

    @Query("SELECT * FROM app WHERE status = 1")
    List<App> getLockedApps();

    @Insert
    void insertAll(App... apps);

    @Update
    void update(App app);

    @Query("UPDATE app SET status = :st")
    void updateAll(Integer st);

    @Delete
    void delete(App app);
}

存储库

@Singleton
public class AppRepository {

    private final AppDao appDao;

    @Inject
    public AppRepository(AppDao appDao) {
        this.appDao = appDao;
    }

    public List<App> getAll() {
        return appDao.getAllApps();
    }

    public List<App> find(String query) {
        return appDao.findApps(query);
    }

    public void insert(App... apps) {
        appDao.insertAll(apps);
    }

    public void update(App app) {
        appDao.update(app);
    }

    public void updateAll(Boolean status) {
        appDao.updateAll(status ? 1 : 0);
    }

    public void delete(App app) {
        appDao.delete(app);
    }
}

这是错误文件

public class StartViewModel extends ViewModel {

    private final AppRepository repository;
    private final PackageManager packageManager;
    private final IconHelper iconHelper;

    private final MutableLiveData<Boolean> status = new MutableLiveData<>();

    @Inject
    StartViewModel(AppRepository repository, PackageManager packageManager) {
        this.repository = repository;
        this.packageManager = packageManager;
        this.iconHelper = new IconHelper(packageManager);
    }

    void updateApps() {
        Intent launcherIntent = new Intent(Intent.ACTION_MAIN, null);
        launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> Resolves = this.packageManager.queryIntentActivities(launcherIntent, 0);

        List<String> AppPackages = new ArrayList<>();
        List<String> ResolvePackages = new ArrayList<>();

        List<App> Apps = repository.getAll(); //Error is here
        for(App a : Apps) AppPackages.add(a.getPackageName());

0 个答案:

没有答案