gpt4 book ai didi

java - 无接口(interface)方法stream()Ljava/util/stream/Stream;

转载 作者:行者123 更新时间:2023-12-01 18:41:49 25 4
gpt4 key购买 nike

我正在尝试过滤我的列表,但我真的不知道出了什么问题。我使用 Java 1.8 来实现 lambda 函数,我的项目 API 我认为是 21;错误:无接口(interface)方法stream()Ljava/util/stream/Stream;在类 Ljava/util/List 中;或其父类(super class)

(“java.util.List”的声明出现在/system/framework/core-libart.jar中) 在 com.example.revizii2020eu.ListaActivity.modifyMyAdapter(ListaActivity.java:98) 在 com.example.revizii2020eu.ListaActivity.access$200(ListaActivity.java:28) 在 com.example.revizii2020eu.ListaActivity$3.onClick(ListaActivity.java:121)

@RequiresApi(api = Build.VERSION_CODES.N)
private void modifyMyAdapter(final String myFirstLetter) {
ArrayList<Revizie> newList = (ArrayList<Revizie>) lista.stream().filter(r -> r.getTip().equalsIgnoreCase(myFirstLetter)).collect(Collectors.toList());
CustomAdapter newAdapter = new CustomAdapter(getApplicationContext(), newList);
mListview.setAdapter(newAdapter);
newAdapter.notifyDataSetChanged();
}
private void filter(){
Etletter = findViewById(R.id.Etsearch); //edittext
btnFilter = findViewById(R.id.buttonFilter);
btnFilter.setOnClickListener(new View.OnClickListener() { //buton de filtu
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View v) {
String myFilterLetter = Etletter.getText().toString();
switch (myFilterLetter){
case "N" :
modifyMyAdapter("Normala");
break;
case "C" :
modifyMyAdapter("Complexa");
break;
case "M" :
modifyMyAdapter("Medie");
break;
case "T" :
CustomAdapter newAdapter = new CustomAdapter(getApplicationContext(), lista);
mListview.setAdapter(newAdapter);
newAdapter.notifyDataSetChanged();
break;
}
}
});

最佳答案

Android 从版本 7 (Nougat) 开始支持 Java 8。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 

// do fillter code here
}else{
show some toast message or thing you need to do
}
}

关于java - 无接口(interface)方法stream()Ljava/util/stream/Stream;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59918060/

25 4 0