Android领域NoSuchMethodError:没有虚方法addChangeListener

时间:2016-10-05 17:58:41

标签: android sqlite realm

由于我将领域的库更新到2.0.0,我的代码已停止工作,我正在使用this教程来实现带有领域的搜索视图 但当我点击进入搜索视图页面时,应用程序崩溃了,这是日志:

10-05 14:45:24.520 1786-1786/com.app E/AndroidRuntime: FATAL EXCEPTION: main
                                                           Process: com.app, PID: 1786
                                                           java.lang.NoSuchMethodError: No virtual method addChangeListener(Lio/realm/RealmChangeListener;)V in class Lio/realm/BaseRealm; or its super classes (declaration of 'io.realm.BaseRealm' appears in /data/data/com.monoapp/files/instant-run/dex/slice-io.realm-realm-android-library-2.0.0_94ee25b8bc2e86a7eff1a547a9e7a3e8b0e46464-classes.dex)
                                                               at io.realm.RealmBasedRecyclerViewAdapter.updateRealmResults(RealmBasedRecyclerViewAdapter.java:331)
                                                               at com.app.RealmSearch.RealmSearchAdapter.filter(RealmSearchAdapter.java:126)
                                                               at com.app.RealmSearch.RealmSearchView.setAdapter(RealmSearchView.java:121)
                                                               at com.app.FragmentSelecionaCliente.showDialog(FragmentSelecionaCliente.java:169)
                                                               at com.app.FragmentSelecionaCliente$2.onClick(FragmentSelecionaCliente.java:105)
                                                               at android.view.View.performClick(View.java:5201)
                                                               at android.view.View$PerformClick.run(View.java:21163)
                                                               at android.os.Handler.handleCallback(Handler.java:746)
                                                               at android.os.Handler.dispatchMessage(Handler.java:95)
                                                               at android.os.Looper.loop(Looper.java:148)
                                                               at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

警告对话框:

 public void showDialog() {

        dialog = new AlertDialog.Builder(getContext());

        dialog.setCancelable(true);

        View view = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.buscar_clientes, null);

        realmSearchView = (RealmSearchView) view.findViewById(R.id.search_view);

        adapter = new SearchRecyclerViewAdapter(getActivity(), mRepositorio.realm, "nome");


        adapter.SetOnItemClickListener(new SearchRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

                TextView nomeCliente = (TextView) view.findViewById(R.id.cliente);
                TextView mCidadestado = (TextView) view.findViewById(R.id.cidadestado);
                TextView mTelefone = (TextView) view.findViewById(R.id.telefone);
                TextView mEmail = (TextView) view.findViewById(R.id.email);
                TextView mClassificacao = (TextView) view.findViewById(R.id.classificacao);
                TextView mIdcliente = (TextView) view.findViewById(R.id.idcliente);

                dialogC.dismiss();
                proximo.setEnabled(true);
                proximo.setAlpha(1);
                nomecliente.setVisibility(View.VISIBLE);
                clientedetalhes.setVisibility(View.VISIBLE);
                nomecliente.setText(nomeCliente.getText());
                cidadestado.setText(mCidadestado.getText());
                telefone.setText(mTelefone.getText());
                email.setText(mEmail.getText());
                classificacao.setText(mClassificacao.getText());
                idcliente.setText(mIdcliente.getText());

                mPessoa = mRepositorio.findPessoa(idcliente.getText().toString());
                libera();

            }
        });

        realmSearchView.setAdapter(adapter);

        dialog.setView(view);
        dialogC = dialog.create();
        dialogC.show();

    }

摇篮

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath "io.realm:realm-gradle-plugin:2.0.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

1 个答案:

答案 0 :(得分:0)

我解决了更新recyclerview库的问题,我正在使用它:

compile 'com.github.thorbenprimke:realm-recyclerview:0.9.16'

我已更新为:

compile 'com.github.thorbenprimke:realm-recyclerview:0.9.23'

现在一切正常。