![](/img/trans.png)
[英]Cannot get all the @override functions such as onStart, onResume in Android Studio
[英]onStart and Override Error in android studio
我編寫了一些代碼來從Firebase獲取數據,但是它顯示了一些錯誤。 我將在下面解釋錯誤並附上圖片。
當我將鼠標放在上面時,出現第一個錯誤,消息顯示: com.abdullrahman.eng.myapp.FriendsFragment中的onon()與android.app.Fragment中的onStart()沖突; 試圖分配較弱的訪問權限(“受保護”); 是“公開”的
當我將鼠標放在上面時,出現第二個錯誤,消息顯示:方法未從其超類覆蓋方法
誰能解決這些問題並為我提供幫助?
編碼:
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Friends, FriendsViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Friends, FriendsViewHolder>(
Friends.class,
R.layout.users_single_layout,
FriendsViewHolder.class,
mUsersDatabase
) {
@Override
protected void populateViewHolder(FriendsViewHolder friendsViewHolder, Friends friends, int position) {
friendsViewHolder.setDisplayName(friends.getName());
friendsViewHolder.setUserStatus(friends.getStatus());
friendsViewHolder.setUserImage(friends.getThumb_image(), mMainView.getContext());
final String user_id = getRef(position).getKey();
friendsViewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent profileIntent = new Intent(getActivity(), UserProfile.class);
profileIntent.putExtra("user_id", user_id);
startActivity(profileIntent);
}
});
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
錯誤確實說明了您遇到的問題。
第一個錯誤是由onStart()方法上protected
訪問修飾符引起的,而該錯誤應該是public
。 它應該是
@Override
publin void onStart() {
super.onStart();
// rest of the code
}
代替
@Override
protected void onStart() {
super.onStart();
// rest of the code
}
您可以在Oracle網站上的文檔中找到有關錯誤原因的更多信息。
第二個問題與FirebaseRecyclerAdapter的定義有關。 看起來好像沒有方法
protected void populateViewHolder(FriendsViewHolder friendsViewHolder, Friends friends, int position).
我建議檢查此類的docs / sources以獲取有關您在項目中使用的Firebase版本的重寫方法應如何顯示的信息。
另外,如我所見,您正在使用IntelliJ IDEA或某些類似的IDE,因此您可以使用內置功能來實現/重寫正確的方法 。
將您的受保護修飾符更改為public,它將消失。
在Java中,與父方法相比,覆蓋方法可以具有相同或較弱的訪問權限...在這里,父類將方法聲明為public,因此您別無選擇,只能用public access修飾符覆蓋它,因為它是最弱的訪問權限可能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.