我在我的应用程序中创建了一个片段,我正在尝试将 firebase 添加到这个片段中。但是由于它使用 onCreateView 的面孔,它正在调用此错误。
public class ProfileFragment extends Fragment {
private DatabaseReference mUserDatabase;
private FirebaseUser mCurrentUser;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_profile, container, false);
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
}
在 mCurrentUser = FirebaseAuth.getInstance().getCurrentUser(); 我收到错误 unreachable 语句 有什么方法可以让我仍然使用片段进行此活动吗?
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_profile, container, false);
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
String current_uid = Objects.requireNonNull(mCurrentUser).getUid();
mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(current_uid);
ValueEventListener valueEventListener = mUserDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String name = dataSnapshot.child("name").getValue().toString();
String image = dataSnapshot.child("image").getValue().toString();
String status = dataSnapshot.child("status").getValue().toString();
String thumb_image = dataSnapshot.child("thumb_image").getValue().toString();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
return view;
});}}
返回视图错误;
holdtom
哔哔one
相关分类