什么是不可及陈述。我不能使用firebasefirestore,而且方法在片段视图中是不可访问的语句。如何使用方法和其他东西以及什么是不可达语句?
private FragmentPostfragBinding binding;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding=FragmentPostfragBinding.inflate(inflater,container,false);
View view=binding.getRoot();
return view;
userview();
}
private void userview() {
FirebaseFirestore db;
db=FirebaseFirestore.getInstance();
DocumentReference ref = db.collection("user").document(FirebaseAuth.getInstance().getCurrentUser().getUid());
ref.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>(){
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if(documentSnapshot.exists()){
String name=documentSnapshot.getString("username");
binding.user.setText(name);
}
else{
Toast.makeText(getActivity(), "Sorry, your information is not saved!", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(getActivity(),otherinfo.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getActivity(), "Error!", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onFailure: "+e.toString());
}
});
}
}
1条答案
按热度按时间szqfcxe21#
“unreachable statement”意味着您有一些在任何情况下都不会运行的代码。对你来说,这是指
userview()
它永远不会运行,因为它遵循return
声明。返回将阻止userview()
从被叫到现在。你需要弄清楚你到底想在这里发生什么,并正确地编码。