java.lang.NoClassDefFoundError:解析失败:Ljava / lang / invoke / MethodType;

时间:2018-04-12 18:46:01

标签: java android gson

我有一个片段从服务器返回一个列表,显示的错误是:

  

java.lang.NoClassDefFoundError:解析失败:Ljava / lang /   invoke / MethodType;

遵循以下所有错误:

04-12 15:22:38.272 30650-30793/br.com.sys.life.atendimento I/HTTP_POST: 1 URL: http://somelink/rest/Agendamento/listarAgendamentos
04-12 15:22:38.272 30650-30793/br.com.sys.life.atendimento I/HTTP_POST: JSON: {"cdProfissional":4}
04-12 15:22:38.337 30650-30793/br.com.sys.life.atendimento I/HTTP_POST: Result: {"retornoMensagem":{"dsTitulo":"Listar Agendamentos.","dsMensagem":"SUCCESS.","dsStackTrace":null,"idCamada":"SUCCESS"},"retorno":[{"cdAgendamento":18,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":141,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"08:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"},{"cdAgendamento":19,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":144,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"09:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"}]}
04-12 15:22:38.344 30650-30650/br.com.sys.life.atendimento E/RecyclerView: No adapter attached; skipping layout
04-12 15:22:38.388 30650-30793/br.com.sys.life.atendimento E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
                                                                                    Process: br.com.sys.life.atendimento, PID: 30650
                                                                                    java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                                        at android.os.AsyncTask$3.done(AsyncTask.java:318)
                                                                                        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                                        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                                        at java.lang.Thread.run(Thread.java:761)
                                                                                     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/invoke/MethodType;
                                                                                        at java.lang.Class.getDeclaredFields(Native Method)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:109)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
                                                                                        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
                                                                                        at com.google.gson.Gson.getAdapter(Gson.java:356)
                                                                                        at com.google.gson.Gson.fromJson(Gson.java:802)
                                                                                        at com.google.gson.Gson.fromJson(Gson.java:868)
                                                                                        at com.google.gson.Gson.fromJson(Gson.java:841)
                                                                                        at br.com.sys.life.atendimento.communication_service.utils.GsonUtil.parseJsonObjectToObject(GsonUtil.java:201)
                                                                                        at br.com.sys.life.atendimento.communication_service.utils.GsonUtil.parseStringJsonToObject(GsonUtil.java:103)
                                                                                        at br.com.sys.life.atendimento.service_atendimento.BaseService.executaPost(BaseService.java:111)
                                                                                        at br.com.sys.life.atendimento.service_atendimento.services.ServiceAgendamentoVo.consultaAgendamentos1(ServiceAgendamentoVo.java:36)
                                                                                        at br.com.sys.life.atendimento.fragments.FragmentFilaAtendimento$AsyncTaskListaAtendimentos.doInBackground(FragmentFilaAtendimento.java:129)
                                                                                        at br.com.sys.life.atendimento.fragments.FragmentFilaAtendimento$AsyncTaskListaAtendimentos.doInBackground(FragmentFilaAtendimento.java:111)
                                                                                        at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                                        at java.lang.Thread.run(Thread.java:761) 
04-12 15:22:38.388 30650-30793/br.com.sys.life.atendimento E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.invoke.MethodType" on path: DexPathList[[zip file "/data/app/br.com.sys.life.atendimento-1/base.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_dependencies_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_0_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_1_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_2_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_3_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_4_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_5_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_6_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_7_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_8_apk.apk", zip file "/data/app/br.com.sys.life.atendimento-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/br.com.sys.life.atendimento-1/lib/arm, /system/lib, /vendor/lib]]
                                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                            ... 36 more
04-12 15:22:38.498 30650-30650/br.com.sys.life.atendimento W/art: Before Android 4.1, method int a

考虑到有问题的错误,我添加了行

builder.registerTypeAdapter(ArrayList.class, new JsonDoubleDeserializer());

builder.registerTypeAdapter(ArrayList.class, new JsonDoubleSerializer());

采用以下createJsonObject方法:

public static Gson createGsonObject() {

        // Formado de data alterado, outro formato não estava convertendo
        // Alterado para setar // na saída devido problema com WebService
        GsonBuilder builder = new GsonBuilder();

        builder.setDateFormat(GsonUtil.FORMAT_DATE).create();

        builder.registerTypeAdapter(Boolean.class,
                new JsonBooleanDeserializer());

        // Tratamento de BigDecimal
        builder.registerTypeAdapter(BigDecimal.class,
                new JsonBigDecimalDeserializer());

        // Tratamento de Byte[]
        builder.registerTypeAdapter(byte[].class,
                new JsonByteArrayDeserializer());

        //Tratamento de deserialização de Date java formato GMT timezone
        builder.registerTypeAdapter(Date.class, new JsonDateDeserializer());

        builder.registerTypeAdapter(Date.class, new JsonDateSerializer());

        //TRATAMENTO DE DOUBLE
        builder.registerTypeAdapter(Double.class, new JsonDoubleDeserializer());

        builder.registerTypeAdapter(Double.class, new JsonDoubleSerializer());

        //ADD TO ARRAY
        builder.registerTypeAdapter(ArrayList.class, new JsonDoubleDeserializer());

        builder.registerTypeAdapter(ArrayList.class, new JsonDoubleSerializer());

        Gson gson = builder.create();

        return gson;
    }

添加这些行时碰巧会出现转换错误,因为我返回一个double但是我问一个arraylist。如果我是正确的,我如何将json转换为返回arraylist?

以下是方法:

   /**
     * Deserialização de ARRAY??????? Java
     */
private static class JsonDoubleSerializer implements JsonSerializer<Double> {

    @Override
    public JsonElement serialize(Double aDouble, java.lang.reflect.Type type, JsonSerializationContext jsonSerializationContext) {
        if (aDouble == aDouble.longValue())
            return new JsonPrimitive(aDouble.longValue());
        return new JsonPrimitive(aDouble);
    }
}
    // ARRAYLIST ?????????????????????????????
    private static class JsonDoubleDeserializer implements
            JsonDeserializer<Double> {

        /*
         * (non-Javadoc)
         *
         * @see
         * com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement
         * , java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
         */
        @Override
        public Double deserialize(JsonElement arg0,
                                  java.lang.reflect.Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {

            String value = arg0.getAsJsonPrimitive().getAsString();

            return new Double(value);
        }
    }

这是我的片段:

 @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

......
        ProfissionalVo profissionalVo = new ProfissionalVo();
        profissionalVo.setCdProfissional(4);
        new AsyncTaskListaAtendimentos(FragmentFilaAtendimento.this.getFragmentManager(), false).execute(profissionalVo);

    }

private class AsyncTaskListaAtendimentos extends BaseAsyncTask<ProfissionalVo,Void,AsyncTaskResult<RetornoAgendamentoVo>>{

    private FragmentManager mFragmentManager;
    private ProfissionalVo profissionalVo;

    public AsyncTaskListaAtendimentos(FragmentManager fragmentManager, boolean isDialogShow) {
        super(fragmentManager, isDialogShow);
        this.mFragmentManager = fragmentManager;

    }

    @Override
    protected AsyncTaskResult doInBackground(ProfissionalVo... profissionalVos) {

        try {
            profissionalVo = profissionalVos[0];

            RetornoAgendamentoVo retorno = ServiceAgendamentoVo.getInstance(MyApplicationInstance.getInstanceApplicationSingleton().getDsChaveAcessoWbs())
                    .consultaAgendamentos1(profissionalVo);

            return new AsyncTaskResult<RetornoAgendamentoVo>(retorno);
        }catch (Exception e){
            return new AsyncTaskResult<Retorno>(e);
        }
    }

    @Override
    protected void onPostExecute(AsyncTaskResult<Retorno> respProfissionalVO) {
        super.onPostExecute(respProfissionalVO);

        if (respProfissionalVO.getExceptionResult() == null && getActivity() != null){
            retornoAgendamentoVo = (RetornoAgendamentoVo) respProfissionalVO.getResult();
            agendamentoVos = new ArrayList<>();
            agendamentoVos = retornoAgendamentoVo.getRetorno();
            // specify an adapter (see also next example)
            mAdapter = new CustomRecyclerViewAdapterFila(agendamentoVos,
                    (AppCompatActivity) getActivity(), this);
        }

    }
}

JSON:

Result: {"retornoMensagem":{"dsTitulo":"Listar Agendamentos.","dsMensagem":"SUCCESS.","dsStackTrace":null,"idCamada":"SUCCESS"},"retorno":[{"cdAgendamento":18,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":141,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"08:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"},{"cdAgendamento":19,"itemAgenda":{"agenda":{"cdAgenda":6,"profissional":{"cdProfissional":4,"nmProfissional":"PROFISSIONAL SAUDE","idConselho":null,"nrConselho":null,"dtCadastro":null,"imgProfissional":null,"idStatus":null,"dsEmail":null,"dsSenha":null,"nmLogin":null,"idEspecialidade":null,"nrCpf":null,"nrRg":null,"nrCns":null,"dsTokenAcesso":null,"dtValidadeTokenAcesso":null,"retonaChaveAcessoWbs":null,"dsChaveAcessoWbs":null},"dtValidadeInicio":null,"dtValidadeFim":null,"hrInicio":null,"hrFim":null,"nrPacientes":null,"tpAgenda":null,"idSeg":null,"idTer":null,"idQua":null,"idQui":null,"idSex":null,"idSab":null,"idDom":null,"idStatus":null,"dtCadastro":null},"cdItemAgenda":144,"dtConsulta":"12/04/2018 00:00:00 -0300","hrConsulta":"09:00","idStatus":null},"paciente":{"cdPaciente":4,"nmPaciente":"PACIENTE TESTE","nmMae":null,"dtNascimento":"10/11/1990 00:00:00 -0200","dtCadastro":null,"tpSexo":"M","dtAtualizacao":null,"dsEmail":null,"dddCelular":null,"nrTelefoneCelular":null,"dddResid":null,"nrTelefoneResid":null,"dsLogradouro":null,"nrResidencia":null,"dsComplemento":null,"dsBairro":null,"dsMunicipio":null,"nrCep":null,"imgPaciente":null,"idStatus":null,"nrCpf":null,"nrRg":null,"nrCns":null},"dtAgendamento":null,"idStatus":"AGENDADO","tpAgendamento":null,"dtAtualizacao":null,"dsObservacao":null,"idClassificacao":"EMERGENCIA"}]}

2 个答案:

答案 0 :(得分:0)

我认为问题确实存在:您编写的代码是什么版本的Java API,以及它实际运行的Java版本是什么?不完全确定,但是我认为整个java.lang.invoke包在Java 7之前都没有引入,所以你可能正在编译Java 7或8,但是在Java 6或更早版本上运行。

答案 1 :(得分:0)

我通过创建以下方法解决了这个问题:

解串器:

 public static Gson createGsonObject() {

        // Formado de data alterado, outro formato não estava convertendo
        // Alterado para setar // na saída devido problema com WebService
        GsonBuilder builder = new GsonBuilder();

....

        //Array
        builder.registerTypeAdapter(List.class, new JsonArrayListDeserializer());

        Gson gson = builder.create();

        return gson;
    }

private static class JsonArrayListDeserializer<T> implements JsonDeserializer<ArrayList<T>>{

    @Override
    public ArrayList<T> deserialize(JsonElement jsonElement, java.lang.reflect.Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        try {

            Gson gson = new Gson();
            TypeToken<ArrayList<T>> token = new TypeToken<ArrayList<T>>() {};
            ArrayList<T> value = gson.fromJson(jsonElement, token.getType());

            return value;
        } catch (ClassCastException e) {
            throw new JsonParseException("Cannot parse json Boolean '"
                    + jsonElement.toString() + "'", e);
        }
    }
}

所以在我看来问题是让json解析。使用这种添加的方法,错误不再出现,数据已经到了应该去的地方。