Java 无法解析方法()

Java 无法解析方法(),java,android,Java,Android,您好,我正在尝试使用创建ExpandableLayout。但是在这行代码中不断出现错误` @Override public void onTextChanged(CharSequence s, int start, int before, int count) { sectionLinearLayout.filterChildren(obj -> ((GradIndjija) obj).name.toLowerCase().cont

您好,我正在尝试使用创建ExpandableLayout。但是在这行代码中不断出现错误`

 @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                sectionLinearLayout.filterChildren(obj -> ((GradIndjija) obj).name.toLowerCase().contains(s.toString().toLowerCase()));
            }
`

我收到了关于filterChildren的消息“无法解析方法filterChildren”,以及关于GradIndjija obj的消息,该消息无法强制转换。 我的代码:`

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import iammert.com.expandablelib.ExpandCollapseListener;
import iammert.com.expandablelib.ExpandableLayout;
import iammert.com.expandablelib.Section;




public class Ogradu extends AppCompatActivity {

    String[] parents = new String[]{"O Indjiji",
            "Istorija Indjije", "Kultura"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.o_gradu);


        EditText editText = (EditText) findViewById(R.id.edittext);
        ExpandableLayout sectionLinearLayout = (ExpandableLayout) findViewById(R.id.el);

        sectionLinearLayout.setRenderer(new ExpandableLayout.Renderer<KategorijaGrada, GradIndjija>() {
            @Override
            public void renderParent(View view, KategorijaGrada model, boolean isExpanded, int parentPosition) {
                ((TextView) view.findViewById(R.id.tv_parent_name)).setText(model.naziv);
                view.findViewById(R.id.arrow).setBackgroundResource(isExpanded ? R.drawable.ic_arrow_up : R.drawable.ic_arrow_down);
            }

            @Override
            public void renderChild(View view, GradIndjija model, int parentPosition, int childPosition) {
                ((TextView) view.findViewById(R.id.tv_child_name)).setText(model.naziv);
            }
        });

        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());
        sectionLinearLayout.addSection(getSection());

        sectionLinearLayout.setExpandListener((ExpandCollapseListener.ExpandListener<KategorijaGrada>) (parentIndex, parent, view) -> {

        });

        sectionLinearLayout.setCollapseListener((ExpandCollapseListener.CollapseListener<KategorijaGrada>) (parentIndex, parent, view) -> {

        });


        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                sectionLinearLayout.filterChildren(obj -> ((GradIndjija) obj).name.toLowerCase().contains(s.toString().toLowerCase()));
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    public Section<KategorijaGrada, GradIndjija> getSection() {
        Section<KategorijaGrada, GradIndjija> section = new Section<>();
        KategorijaGrada kategorijeGrada = new KategorijaGrada(parents[(int) (Math.random() * parents.length)]);
        GradIndjija grad1 = new GradIndjija("Istorija Grada");
        GradIndjija grad2 = new GradIndjija("O Indjiji");
        GradIndjija grad3 = new GradIndjija("Kultura grada");

        section.parent = kategorijeGrada;
        section.children.add(grad1);
        section.children.add(grad2);
        section.children.add(grad3);
        section.expanded = true;
        return section;
    }
}
` 我在我的logcat中没有收到任何错误消息,因为应用程序甚至还没有启动。我只在我的消息gradle build中收到错误:

    C:\Users\Korisnik\Downloads\ud839_Miwok-Starter-code\IndjijaVodic\app\src\main\java\com\example\korisnik\indjijavodic\Ogradu.java
Error:(75, 36) error: cannot find symbol method filterChildren((obj)->((G[...]se()))
Error:(75, 78) error: cannot find symbol variable name
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
GradIndjija.java:`

    package com.example.korisnik.indjijavodic;

    public class GradIndjija {
       public String kategorija;

        public GradIndjija(String naziv) {
            this.naziv = naziv;
        }
    }

`

and my second class KategorijaGrada:`package com.example.korisnik.indjijavodic;

/**
 * Created by Korisnik on 23.7.2018..
 */

public class KategorijaGrada {
    public String naziv;

    public KategorijaGrada(String naziv) {
        this.naziv = naziv;
    }
}
`


我昨天用谷歌搜索了一整天,并尝试了我知道的所有东西,虽然我知道的东西我都试过了,但是我知道的不多,所以任何帮助都非常感谢,因为字段名未定义,所以您无法编译

首先,GradIndjija类应该是这样的:

public class GradIndjija {
   // naziv instead of kategorija
   public String nziv;

    public GradIndjija(String naziv) {
        this.naziv = naziv;
    }
}
   public void onTextChanged(CharSequence s, int start, int before, int count) {
      //naziv instead of name
      sectionLinearLayout.filterChildren(obj -> ((GradIndjija) obj).naziv.toLowerCase().contains(s.toString().toLowerCase()));
   }
过滤器函数的外观应如下所示:

public class GradIndjija {
   // naziv instead of kategorija
   public String nziv;

    public GradIndjija(String naziv) {
        this.naziv = naziv;
    }
}
   public void onTextChanged(CharSequence s, int start, int before, int count) {
      //naziv instead of name
      sectionLinearLayout.filterChildren(obj -> ((GradIndjija) obj).naziv.toLowerCase().contains(s.toString().toLowerCase()));
   }

希望能有所帮助。

一切似乎都是正确的。你能粘贴你的日志和gradle文件吗?@maheryhaja这里我编辑了我的问题和pu gradle文件..非常感谢你能粘贴你的GradIndjija类吗。问题可能来自于这两个类