其他分享
首页 > 其他分享> > 解析失败:Landroid / arch / core / executor / AppToolkitTaskExecutor

解析失败:Landroid / arch / core / executor / AppToolkitTaskExecutor

作者:互联网

我目前正在尝试使用Retrofit2设置Room.我想将数据从Retrofit2插入到Room数据库中,但插入对我来说不起作用,应用程序崩溃了.我使用Room Library实现了三个组件:实体,Dao和数据库.

我有结果这个错误.

E / AndroidRuntime:致命异常:主要
                  处理:com.example.a694532.e_controlling,PID:31841
                  java.lang.NoClassDefFoundError:解析失败:Landroid / arch / core / executor / AppToolkitTaskExecutor;
                      在android.arch.persistence.room.InvalidationTracker.refreshVersionsAsync(InvalidationTracker.java:403)
                      在android.arch.persistence.room.RoomDatabase.endTransaction(RoomDatabase.java:219)
                      在com.example.a694532.e_controlling.data.db.dao.GareDao_Impl.insertGares(GareDao_Impl.java:116)
                      at com.example.a694532.e_controlling.service.repository.TotoRepository $1.onResponse(TotoRepository.java:106)
                      at retrofit2.ExecutorCallAdapterFactory $ExecutorCallbackCall $1 $1.run(ExecutorCallAdapterFactory.java:70)
                      在android.os.Handler.handleCallback(Handler.java:739)
                      在android.os.Handler.dispatchMessage(Handler.java:95)
                      在android.os.Looper.loop(Looper.java:158)
                      在android.app.ActivityThread.main(ActivityThread.java:7224)
                      at java.lang.reflect.Method.invoke(Native Method)
                      在com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:1230)
                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                   引起:java.lang.ClassNotFoundException:路径上没有找到类“android.arch.core.executor.AppToolkitTaskExecutor”:DexPathList [[zip file“/data/app/com.example.a694532.e_controlling-2/base .apk“,zip文件”/data/app/com.example.a694532.e_controlling-2/split_lib_dependencies_apk.apk“,zip文件”/data/app/com.example.a694532.e_controlling-2/split_lib_slice_0_apk.apk“, zip文件“/data/app/com.example.a694532.e_controlling-2/split_lib_slice_1_apk.apk”,zip文件“/data/app/com.example.a694532.e_controlling-2/split_lib_slice_2_apk.apk”,zip文件“/ data / app / com.example.a694532.e_controlling-2 / split_lib_slice_3_apk.apk“,zip file”/data/app/com.example.a694532.e_controlling-2/split_lib_slice_4_apk.apk“,zip file”/ data / app / com.example.a694532.e_controlling-2 / split_lib_slice_5_apk.apk“,zip文件”/data/app/com.example.a694532.e_controlling-2/split_lib_slice_6_apk.apk“,zip文件”/data/app/com.example. a694532.e_controlling-2 / split_lib_slice_7_apk.apk“,zip file”/data/app/com.example.a69 4532.e_controlling-2 / split_lib_slice_8_apk.apk“,zip文件”/data/app/com.example.a694532.e_controlling-2/split_lib_slice_9_apk.apk\”],nativeLibraryDirectories=[/data/app/com.example.a694532.e_controlling -2 / lib / arm,/ vendor / lib,/ system / lib]]
                      在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                      在android.arch.persistence.room.InvalidationTracker.refreshVersionsAsync(InvalidationTracker.java:403)
                      在android.arch.persistence.room.RoomDatabase.endTransaction(RoomDatabase.java:219)
                      在com.example.a694532.e_controlling.data.db.dao.GareDao_Impl.insertGares(GareDao_Impl.java:116)
                      at com.example.a694532.e_controlling.service.repository.TotoRepository $1.onResponse(TotoRepository.java:106)
                      at retrofit2.ExecutorCallAdapterFactory $ExecutorCallbackCall $1 $1.run(ExecutorCallAdapterFactory.java:70)
                      在android.os.Handler.handleCallback(Handler.java:739)
                      在android.os.Handler.dispatchMessage(Handler.java:95)
                      在android.os.Looper.loop(Looper.java:158)
                      在android.app.ActivityThread.main(ActivityThread.java:7224)
                      at java.lang.reflect.Method.invoke(Native Method)
                      在com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:1230)
                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                    抑制: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)
                            ……还有13个
                   引起:java.lang.NoClassDefFoundError:使用引导类加载器找不到类;没有堆栈跟踪可用

Repository.class

 @Singleton
public class TotoRepository {

    //Converters
    private GareDtoConverter mGareConverter = new GareDtoConverter();
    private TrainDuJourDtoConverter mTrainDuJourConverter = new TrainDuJourDtoConverter();

    private TotoService totoService;
    private Executor executor;
    private GareDao gareDao;
    private TrainDao trainDao;
    private TronconDao tronconDao;
    GareEtTrainDuJour mGareEtTrain=new GareEtTrainDuJour();

    MyDatabase database;

    OkHttpClient okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();

    public TotoRepository (Application application) {
        Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                .create();
        Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl(EndPoint.TICKET)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create(gson));
        Retrofit retrofit = builder.build();
        totoService = retrofit.create(TotoService.class);
        database = MyDatabase.getInstance(application);
        gareDao=database.garesDao();
        trainDao=database.trainDao();
        tronconDao=database.tronconDao();


    }

    /*
    @Inject
    public TotoRepository(TotoService totoService, GareDao gareDao,TrainDao trainDao,TronconDao tronconDao, Executor executor) {
        this.totoService=totoService;
        this.gareDao=gareDao;
        this.trainDao=trainDao;
        this.tronconDao=tronconDao;
        this.executor = executor;
    }*/


public GareEtTrainDuJour getGareEtTrainDuJour() {
    refreshGareEtTrainDuJour();
    // return a LiveData directly from the database.
    Log.d("loadFromDb","Recuperation des gares et trains du jours depuis la BD");

     mGareEtTrain.setGareList(gareDao.getGares());
     mGareEtTrain.setTrainList(trainDao.getTrains());
     mGareEtTrain.setTronconList(tronconDao.getTroncons());

     return mGareEtTrain;

}




    public void refreshGareEtTrainDuJour(){

        totoService.garesEtTrainsDuJour().enqueue(new Callback<GaresEtTrainsDuJourDTO>() {
            @Override
            public void onResponse(Call<GaresEtTrainsDuJourDTO> call, Response<GaresEtTrainsDuJourDTO> response) {

                gareDao.insertGares(mGareConverter.toModelList(response.body().getGares()));
                Map<String, Gare> listNameGare = mGareConverter.myListMapper(mGareConverter.toModelList(response.body().getGares()));
                trainDao.insertOrReplaceTrains(mTrainDuJourConverter.toTrainModelList(response.body().getTrains(),listNameGare));
                Log.d("RBRBRBRBRB",mTrainDuJourConverter.toTrainModelList(response.body().getTrains(),listNameGare).toString());


            }

            @Override
            public void onFailure(Call<GaresEtTrainsDuJourDTO> call, Throwable t) {
                Log.d("RBRBRBRBRBFFFF",t.getCause().toString());
                Log.d("RBRBRBRBRBFFFF",t.toString());
                t.printStackTrace();



            }
        });
    }

}

ViewModel.class

public class TotoViewModel extends AndroidViewModel {

private GareEtTrainDuJour mGareEtTrain;
private TotoRepository totoRepo;

@Inject
public TotoViewModel(Application application) {
    super(application);
    totoRepo=new TotoRepository(application);
}

public void init() {
    mGareEtTrain=totoRepo.getGareEtTrainDuJour();
}



public GareEtTrainDuJour getGaresTrain() {
    return this.mGareEtTrain;
}

}

解决方法:

我只是将gradle依赖项设置为最新版本并且可以正常工作.

的build.gradle(项目级)

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.1'
    classpath 'com.google.gms:google-services:4.2.0'
}

的build.gradle(应用级)

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
}

标签:android-room,android,retrofit2,android-livedata,livecycle
来源: https://codeday.me/bug/20190910/1799731.html