delete生成一个exeption java

6tqwzwtp  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(328)

在应用程序中,我创建了不同的table和房间。我使用其中一个来保存用户在注册期间输入的区域,然后将这些区域添加到注册表单中的微调器中。在这个片段中,我使用了@delete,直到今天,它的效果还不错。我没有改变任何逻辑,甚至没有访问这个片段。当我注解掉代码的这个删除部分时,房间本身似乎工作得很好。求求你,救命!这是我的代码和日志。

@Dao
public interface RegionDao {
    @Query("SELECT * FROM Region")
    Cursor getAll();

    @Insert
    void insertAll(Region... regions);

    @Query("SELECT COUNT(*) from Region")
    int countRegions();

    @Delete
    void nukeTable(Region... regions);
}

**当exepton发生的时候,我以前用这个代码作为一个delete方法,正如网站上的一个答案所建议的,但是后来按照文档的建议修改了它,结果是一样的

@Query("DELETE FROM Region")
    public void nukeTable();

    public class Fragment2 extends Fragment {

        AppDatabase myDB;
        .......
       @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup 
        container,
                                 Bundle savedInstanceState) {
           ..............................
            mAuth = FirebaseAuth.getInstance();
            ..
            initDB();
            myDB.regionDao().nukeTable();
            if (myDB.regionDao().countRegions() == 0) {
                addRegion();
            } 
         @Override
         public void onDestroy() {

            super.onDestroy();
            myDB.close();
        }

        private void initDB() {
            myDB = Room.databaseBuilder(getContext(),
                    AppDatabase.class, 
       "DataBase").allowMainThreadQueries().build();

        }

        public void addRegion() {
            Region newRegion1 = new Region();
            Region newRegion2 = new Region();
            Region newRegion3 = new Region();
            Region newRegion4 = new Region();
            Region newRegion5 = new Region();
            Region newRegion6 = new Region();

            newRegion1.setRegion("Alaska");
            newRegion2.setRegion("Texas");
            newRegion3.setRegion("Columbia");
            newRegion4.setRegion("Utah");
            newRegion5.setRegion("California");
            newRegion6.setRegion("Florida");

            myDB.regionDao().insertAll(newRegion1);
            myDB.regionDao().insertAll(newRegion2);
            myDB.regionDao().insertAll(newRegion3);
            myDB.regionDao().insertAll(newRegion4);
            myDB.regionDao().insertAll(newRegion5);
            myDB.regionDao().insertAll(newRegion6);
        }

日志:

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/core/executor/AppToolkitTaskExecutor;
                                                                        at android.arch.persistence.room.InvalidationTracker.refreshVersionsAsync(InvalidationTracker.java:403)
                                                                        at android.arch.persistence.room.RoomDatabase.endTransaction(RoomDatabase.java:219)
                                                                        at com.anastacia.test_2.room.RegionDao_Impl.nukeTable(RegionDao_Impl.java:70)
                                                                        at com.anastacia.test_2.Fragments.Fragment2.onCreateView(Fragment2.java:74)
                                                                        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
                                                                        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
                                                                        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
                                                                        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
                                                                        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
                                                                        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
                                                                        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
                                                                        at android.os.Handler.handleCallback(Handler.java:815)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                        at android.os.Looper.loop(Looper.java:207)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5791)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
                                                                     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.core.executor.AppToolkitTaskExecutor" on path: DexPathList[[zip file "/data/app/com.anastacia.test_2-2/base.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.anastacia.test_2-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.anastacia.test_2-2/lib/arm64, /vendor/lib64, /system/lib64]]
                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                        at android.arch.persistence.room.InvalidationTracker.refreshVersionsAsync(InvalidationTracker.java:403) 
                                                                        at android.arch.persistence.room.RoomDatabase.endTransaction(RoomDatabase.java:219) 
                                                                        at com.anastacia.test_2.room.RegionDao_Impl.nukeTable(RegionDao_Impl.java:70) 
                                                                        at com.anastacia.test_2.Fragments.Fragment2.onCreateView(Fragment2.java:74) 
                                                                        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354) 
                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) 
                                                                        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740) 
                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809) 
                                                                        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799) 
                                                                        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580) 
                                                                        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367) 
                                                                        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322) 
                                                                        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229) 
                                                                        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700) 
                                                                        at android.os.Handler.handleCallback(Handler.java:815) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:104) 
                                                                        at android.os.Looper.loop(Looper.java:207) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5791) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 
                                                                        Suppressed: java.lang.ClassNotFoundException: android.arch.core.executor.AppToolkitTaskExecutor
                                                                        at java.lang.Class.classForName(Native Method)
                                                                        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
kcwpcxri

kcwpcxri1#

日志引用找不到类“android.arch.core.executor.apptoolkittaskexecutor”这是来自“android.arch”的类。lifecycle:compiler,请检查您的gradle并确保所有组件依赖项都是最新版本,即“android.arch”。lifecycle:compiler:1.0.0-rc1“从今天起
您可以在下面的超链接中检查所有组件依赖项版本
向项目中添加架构组件-google开发者
希望有帮助。

相关问题