英文:
Cannot resolve method 'getCurrentList' in 'FirebaseRecyclerOptions'
问题
我正在开发一个大学搜索应用程序,但我无法解决这个错误。
以下是代码:
```java
public class searchEngineActivity extends AppCompatActivity {
// ... (其他代码部分未翻译)
**databaseReference = adapter.getRef(position);**
databaseReference = databaseReference.child(queryCourse);
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String queryURL = dataSnapshot.getValue(String.class);
queryURL = queryURL.replaceAll("state", queryState);
webView.loadUrl(queryURL);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
return viewHolder;
}
};
searchRecyclerView.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerPagingAdapter<Object, RecyclerView.ViewHolder> firebaseRecyclerAdapter = null;
firebaseRecyclerAdapter.startListening();
} //UPDATING RECYCLER VIEW REGULARLY FROM THE START OF FRAGMENT
}
英文:
I am working on a college search app and I am unable to solve this error.
Here is the code:
public class searchEngineActivity extends AppCompatActivity {
public String stateSelected;
public String courseSelected;
public RecyclerView searchRecyclerView;
public WebView webView;
public FirebaseRecyclerOptions adapter;
public DatabaseReference databaseReference;
String queryState, queryCourse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_engine);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
Bundle bundle = getIntent().getExtras();
stateSelected = bundle.getString("stateSelected");
courseSelected = bundle.getString("courseSelected");
Log.e("arguments",stateSelected+courseSelected );
makeQuery(stateSelected, courseSelected);
searchRecyclerView = (RecyclerView) findViewById(R.id.searchRecyclerView);
webView = (WebView) findViewById(R.id.webView);
searchRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
setAdapter();
searchRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));
}
public void makeQuery(String q, String c) {
queryState = q.replaceAll(" ", "-");
queryState = queryState.toLowerCase();
queryCourse = c.toLowerCase();
}
public void setAdapter() {
Query query = FirebaseDatabase.getInstance().getReference().child("searchengines");
FirebaseRecyclerOptions<searchModelClass> options = new FirebaseRecyclerOptions.Builder<searchModelClass>().setQuery(query, searchModelClass.class).build();
adapter = new FirebaseRecyclerPagingAdapter<searchModelClass, androidx.recyclerview.widget.RecyclerView.ViewHolder>(options) {
//@Override
protected void onBindViewHolder(@NonNull searchRecyclerViewHolder holder, final int position, @NonNull searchModelClass model) {
holder.setSiteImage(model.getImage());
holder.setSiteName(model.getName());
holder.setSiteURL(model.getUrl());
}
@Override
protected void onBindViewHolder(@androidx.annotation.NonNull @NonNull RecyclerView.ViewHolder viewHolder, int position, @androidx.annotation.NonNull @NonNull searchModelClass model) {
}
@Override
protected void onLoadingStateChanged(@androidx.annotation.NonNull @NonNull LoadingState state) {
}
@NonNull
//@Override
public searchRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.search_recycler_view, parent, false);
final searchRecyclerViewHolder viewHolder = new searchRecyclerViewHolder(view);
viewHolder.setOnClickListener(new searchRecyclerViewHolder.ClickListener() {
@Override
public void onClick(View view, int position) {
**databaseReference = adapter.getCurrentList(position);**
databaseReference = databaseReference.child(queryCourse);
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String queryURL = dataSnapshot.getValue(String.class);
queryURL = queryURL.replaceAll("state", queryState);
webView.loadUrl(queryURL);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
return viewHolder;
}
};
searchRecyclerView.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerPagingAdapter<Object, RecyclerView.ViewHolder> firebaseRecyclerAdapter = null;
firebaseRecyclerAdapter.startListening();
} //UPDATING RECYCLER VIEW REGULARLY FROM THE START OF FRAGMENT
}
Error is:
> Cannot resolve method 'getCurrentList' in 'FirebaseRecyclerOptions':101
I tried to use other library for recycler view in place of firebase ui library, but then I have to change my whole code. What else I can do?
答案1
得分: 1
你的 adapter
对象是一个 FirebaseRecyclerPagingAdapter
类型的对象。当你在这样的对象上尝试调用 getCurrentList(position)
时,得到以下错误是预期的行为:
在 'FirebaseRecyclerOptions' 中无法解析方法 'getCurrentList':101
因为在你的适配器类中不存在 getCurrentList()
方法。而且,如果存在这样一个方法,如其名字所示,它应该返回一个列表而不是一个 DatabaseReference
对象。所以根据你的代码,产生该错误的那行代码应该被移除。
英文:
Your adapter
object is an object of type FirebaseRecyclerPagingAdapter
. When you try to call getCurrentList(position)
on such an object, it's the expected behavior to get the following error:
Cannot resolve method 'getCurrentList' in 'FirebaseRecyclerOptions':101
Since there is no getCurrentList()
method inside your adapter class. Moreover, if such a method existed, as the name says, it would have returned a list and not a DatabaseReference
object. So seeing your code, that line of code that produces that error should be removed.
答案2
得分: 0
你是否正在寻找getRef()
?它将是:
databaseReference = adapter.getRef(position);
我强烈建议在这种情况下保持你所使用的类的源代码随手可得,因为整个FirebaseAdapter.java
文件只有47行,可以快速帮助你找到存在和不存在的内容。
英文:
Are you looking for getRef()
? That'd be:
databaseReference = adapter.getRef(position);
I highly recommend keeping the source code for the class you're using handy in cases like this, as the entire FirebaseAdapter.java
file is only 47 lines long and can quickly help you find what does and what doesn't exist.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论