Java 我的Android应用程序中存在异常意图或Firebase错误

Java 我的Android应用程序中存在异常意图或Firebase错误,java,android,firebase,android-intent,Java,Android,Firebase,Android Intent,嗨,我的社区! 我是Java和Android编程的初学者,但我学得很快。最近我犯了一个很奇怪的错误。我不知道这是什么错误。绝对没有代码或logcat错误。我认为整个情况可能是关于ProfileFragment意图连接以下fragment(在一个奇怪的事件转折中,这是有意扩展AppCompatActivity类)。我想我的Firebase使用也可能有bug,但我真的不知道。但这是对这个错误的一种解释:在所述片段之后,没有显示任何内容,只有空白。应显示以下用户。没有发生崩溃,也没有logcat错误,

嗨,我的社区! 我是Java和Android编程的初学者,但我学得很快。最近我犯了一个很奇怪的错误。我不知道这是什么错误。绝对没有代码或logcat错误。我认为整个情况可能是关于ProfileFragment意图连接以下fragment(在一个奇怪的事件转折中,这是有意扩展AppCompatActivity类)。我想我的Firebase使用也可能有bug,但我真的不知道。但这是对这个错误的一种解释:在所述片段之后,没有显示任何内容,只有空白。应显示以下用户。没有发生崩溃,也没有logcat错误,通常什么都没有。怎么了?这是我的密码: ProfileFragment:

public class ProfileFragment extends Fragment {

    private static final String TAG = "ProfileFragment";


    public interface OnGridImageSelectedListener{
        void onGridImageSelected(Photo photo, int activityNumber);
    }
    OnGridImageSelectedListener mOnGridImageSelectedListener;

    private static final int ACTIVITY_NUM = 4;
    private static final int NUM_GRID_COLUMNS = 3;

    //firebase
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;
    private FirebaseDatabase mFirebaseDatabase;
    private DatabaseReference myRef;
    private FirebaseMethods mFirebaseMethods;


    //widgets
    private TextView mPosts, mFollowers, mFollowing, mDisplayName, mUsername, mWebsite, mDescription;
    private ProgressBar mProgressBar;
    private CircleImageView mProfilePhoto;
    private GridView gridView;
    private Toolbar toolbar;
    private ImageView profileMenu;
    private BottomNavigationViewEx bottomNavigationView;
    private Context mContext;


    static class ViewHolder{

    User user = new User();
    }
    ViewHolder holder = new ViewHolder();

    //vars
    private int mFollowersCount = 0;
    private int mFollowingCount = 0;
    private int mPostsCount = 0;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);
        mDisplayName = (TextView) view.findViewById(R.id.display_name);
        mUsername = (TextView) view.findViewById(R.id.username);
        mWebsite = (TextView) view.findViewById(R.id.website);
        mDescription = (TextView) view.findViewById(R.id.description);
        mProfilePhoto = (CircleImageView) view.findViewById(R.id.profile_photo);
        mPosts = (TextView) view.findViewById(R.id.tvPosts);
        mFollowers = (TextView) view.findViewById(R.id.tvFollowers);
        mFollowing = (TextView) view.findViewById(R.id.tvFollowing);
        mProgressBar = (ProgressBar) view.findViewById(R.id.profileProgressBar);
        gridView = (GridView) view.findViewById(R.id.gridView);
        toolbar = (Toolbar) view.findViewById(R.id.profileToolBar);
        profileMenu = (ImageView) view.findViewById(R.id.profileMenu);
        bottomNavigationView = (BottomNavigationViewEx) view.findViewById(R.id.bottomNavViewBar);
        mContext = getActivity();
        mFirebaseMethods = new FirebaseMethods(getActivity());
        Log.d(TAG, "onCreateView: stared.");


        setupBottomNavigationView();
        setupToolbar();

        setupFirebaseAuth();
        setupGridView();

        getFollowersCount();
        getFollowingCount();
        getPostsCount();



        TextView editProfile = (TextView) view.findViewById(R.id.textEditProfile);
        editProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick: navigating to " + mContext.getString(R.string.edit_profile_fragment));
                Intent intent = new Intent(getActivity(), AccountSettingsActivity.class);
                intent.putExtra(getString(R.string.calling_activity), getString(R.string.profile_activity));
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        });

       // TextView mFollowing = (TextView) view.findViewById(R.id.tvFollowing);
        mFollowing.setOnClickListener(new View.OnClickListener() {


            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), FollowingFragment.class);
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);




            }



        });



        return view;

    }


    @Override
    public void onAttach(Context context) {
        try{
            mOnGridImageSelectedListener = (OnGridImageSelectedListener) getActivity();
        }catch (ClassCastException e){
            Log.e(TAG, "onAttach: ClassCastException: " + e.getMessage() );
        }
        super.onAttach(context);
    }

    private void setupGridView(){
        Log.d(TAG, "setupGridView: Setting up image grid.");

        final ArrayList<Photo> photos = new ArrayList<>();
        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
        Query query = reference
                .child(getString(R.string.dbname_user_photos))
                .child(FirebaseAuth.getInstance().getCurrentUser().getUid());
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for ( DataSnapshot singleSnapshot :  dataSnapshot.getChildren()){

                    Photo photo = new Photo();
                    Map<String, Object> objectMap = (HashMap<String, Object>) singleSnapshot.getValue();

                    try {
                        photo.setCaption(objectMap.get(getString(R.string.field_caption)).toString());
                        photo.setTags(objectMap.get(getString(R.string.field_tags)).toString());
                        photo.setPhoto_id(objectMap.get(getString(R.string.field_photo_id)).toString());
                        photo.setUser_id(objectMap.get(getString(R.string.field_user_id)).toString());
                        photo.setDate_created(objectMap.get(getString(R.string.field_date_created)).toString());
                        photo.setImage_path(objectMap.get(getString(R.string.field_image_path)).toString());

                        ArrayList<Comment> comments = new ArrayList<Comment>();
                        for (DataSnapshot dSnapshot : singleSnapshot
                                .child(getString(R.string.field_comments)).getChildren()) {
                            Comment comment = new Comment();
                            comment.setUser_id(dSnapshot.getValue(Comment.class).getUser_id());
                            comment.setComment(dSnapshot.getValue(Comment.class).getComment());
                            comment.setDate_created(dSnapshot.getValue(Comment.class).getDate_created());
                            comments.add(comment);
                        }

                        photo.setComments(comments);

                        List<Like> likesList = new ArrayList<Like>();
                        for (DataSnapshot dSnapshot : singleSnapshot
                                .child(getString(R.string.field_likes)).getChildren()) {
                            Like like = new Like();
                            like.setUser_id(dSnapshot.getValue(Like.class).getUser_id());
                            likesList.add(like);
                        }
                        photo.setLikes(likesList);
                        photos.add(photo);
                    }catch(NullPointerException e){
                        Log.e(TAG, "onDataChange: NullPointerException: " + e.getMessage() );
                    }
                }

                //setup our image grid
                int gridWidth = getResources().getDisplayMetrics().widthPixels;
                int imageWidth = gridWidth/NUM_GRID_COLUMNS;
                gridView.setColumnWidth(imageWidth);

                ArrayList<String> imgUrls = new ArrayList<String>();
                for(int i = 0; i < photos.size(); i++){
                    imgUrls.add(photos.get(i).getImage_path());
                }
                GridImageAdapter adapter = new GridImageAdapter(getActivity(),R.layout.layout_grid_imageview,
                        "", imgUrls);
                gridView.setAdapter(adapter);

                gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        mOnGridImageSelectedListener.onGridImageSelected(photos.get(position), ACTIVITY_NUM);
                    }
                });
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.d(TAG, "onCancelled: query cancelled.");
            }
        });
    }

    private void getFollowersCount(){
        mFollowersCount = 0;

        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
        Query query = reference.child(getString(R.string.dbname_followers))
                .child(FirebaseAuth.getInstance().getCurrentUser().getUid());
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot singleSnapshot :  dataSnapshot.getChildren()){
                    Log.d(TAG, "onDataChange: found follower:" + singleSnapshot.getValue());
                    mFollowersCount++;
                }
                mFollowers.setText(String.valueOf(mFollowersCount));
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
    /*Query userQuery = mReference
            .child(mContext.getString(R.string.dbname_users))
            .orderByChild(mContext.getString(R.string.field_user_id))
            .equalTo(getItem(position).getUser_id());
        userQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
                Log.d(TAG, "onDataChange: found user: " +
                        singleSnapshot.getValue(User.class).getUsername());

                holder.user = singleSnapshot.getValue(User.class);
            }

        } */
    private void getFollowingCount(){
        mFollowingCount = 0;

        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
        Query query = reference.child(getString(R.string.dbname_following))
                .child(FirebaseAuth.getInstance().getCurrentUser().getUid());
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot singleSnapshot :  dataSnapshot.getChildren()){
                    Log.d(TAG, "onDataChange: found following user:" + singleSnapshot.getValue());
                    mFollowingCount++;
                }
                mFollowing.setText(String.valueOf(mFollowingCount));
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

    private void getPostsCount(){
        mPostsCount = 0;

        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
        Query query = reference.child(getString(R.string.dbname_user_photos))
                .child(FirebaseAuth.getInstance().getCurrentUser().getUid());
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot singleSnapshot :  dataSnapshot.getChildren()){
                    Log.d(TAG, "onDataChange: found post:" + singleSnapshot.getValue());
                    mPostsCount++;
                }
                mPosts.setText(String.valueOf(mPostsCount));
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

    private void setProfileWidgets(UserSettings userSettings) {
        //Log.d(TAG, "setProfileWidgets: setting widgets with data retrieving from firebase database: " + userSettings.toString());
        //Log.d(TAG, "setProfileWidgets: setting widgets with data retrieving from firebase database: " + userSettings.getSettings().getUsername());


        //User user = userSettings.getUser();
        UserAccountSettings settings = userSettings.getSettings();

        UniversalImageLoader.setImage(settings.getProfile_photo(), mProfilePhoto, null, "");

        mDisplayName.setText(settings.getDisplay_name());
        mUsername.setText(settings.getUsername());
        mWebsite.setText(settings.getWebsite());
        mDescription.setText(settings.getDescription());
        mProgressBar.setVisibility(View.GONE);
    }


    /**
     * Responsible for setting up the profile toolbar
     */
    private void setupToolbar(){

        ((ProfileActivity)getActivity()).setSupportActionBar(toolbar);

        profileMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick: navigating to account settings.");
                Intent intent = new Intent(mContext, AccountSettingsActivity.class);
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        });
    }

    /**
     * BottomNavigationView setup
     */
    private void setupBottomNavigationView(){
        Log.d(TAG, "setupBottomNavigationView: setting up BottomNavigationView");
        BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationView);
        BottomNavigationViewHelper.enableNavigation(mContext,getActivity() ,bottomNavigationView);
        Menu menu = bottomNavigationView.getMenu();
        MenuItem menuItem = menu.getItem(ACTIVITY_NUM);
        menuItem.setChecked(true);
    }

      /*
    ------------------------------------ Firebase ---------------------------------------------
     */

    /**
     * Setup the firebase auth object
     */
    private void setupFirebaseAuth(){
        Log.d(TAG, "setupFirebaseAuth: setting up firebase auth.");

        mAuth = FirebaseAuth.getInstance();
        mFirebaseDatabase = FirebaseDatabase.getInstance();
        myRef = mFirebaseDatabase.getReference();

        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();


                if (user != null) {
                    // User is signed in
                    Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                }
                // ...
            }
        };


        myRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                //retrieve user information from the database
                setProfileWidgets(mFirebaseMethods.getUserSettings(dataSnapshot));

                //retrieve images for the user in question

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }


    @Override
    public void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mAuthListener != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }


}
公共类ProfileFragment扩展了片段{
私有静态最终字符串TAG=“ProfileFragment”;
公共接口OnGridImageSelectedListener{
所选图像无效(照片、int活动编号);
}
OnGridImageSelectedListener mOnGridImageSelectedListener;
私有静态最终整数活动_NUM=4;
私有静态final int NUM_GRID_COLUMNS=3;
//火基
私人消防队;
私有FirebaseAuth.AuthStateListener mAuthListener;
私有FirebaseDatabase mFirebaseDatabase;
私有数据库参考myRef;
私有FirebaseMethods mFirebaseMethods;
//小部件
私有文本视图mpost、mFollowers、mFollow、mDisplayName、mUsername、mWebsite、MDDescription;
私人ProgressBar mProgressBar;
私人CircleImageView mProfilePhoto;
私有GridView GridView;
专用工具栏;
私有图像查看配置文件菜单;
私有BottomNavigationViewEx bottomNavigationView;
私有上下文;
静态类视窗夹{
用户=新用户();
}
ViewHolder=新的ViewHolder();
//瓦尔斯
私有int mFollowersCount=0;
私有int mFollowingCount=0;
私有int MPostScont=0;
@可空
@凌驾
创建视图时的公共视图(LayoutFlater充气机、@Nullable ViewGroup容器、@Nullable Bundle savedInstanceState){
视图=充气机。充气(R.layout.fragment_外形,容器,假);
mDisplayName=(TextView)view.findViewById(R.id.display\u name);
mUsername=(TextView)view.findViewById(R.id.username);
mWebsite=(TextView)view.findViewById(R.id.website);
mddescription=(TextView)view.findViewById(R.id.description);
mProfilePhoto=(CircleImageView)view.findViewById(R.id.profile_photo);
mPosts=(TextView)view.findViewById(R.id.tvPosts);
mFollowers=(TextView)view.findViewById(R.id.tvFollowers);
mfollow=(TextView)view.findViewById(R.id.tvFollowing);
mProgressBar=(ProgressBar)view.findviewbyd(R.id.profileProgressBar);
gridView=(gridView)view.findViewById(R.id.gridView);
toolbar=(toolbar)view.findviewbyd(R.id.profileToolBar);
profileMenu=(ImageView)view.findViewById(R.id.profileMenu);
bottomNavigationView=(BottomNavigationViewEx)view.findViewById(R.id.bottomNavViewBar);
mContext=getActivity();
mFirebaseMethods=新的FirebaseMethods(getActivity());
Log.d(标记“onCreateView:Started”);
setupBottomNavigationView();
设置工具栏();
setupFirebaseAuth();
setupGridView();
getFollowersCount();
getCount();
getPostScont();
TextView editProfile=(TextView)view.findViewById(R.id.textEditProfile);
editProfile.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
d(标记“onClick:导航到”+mContext.getString(R.string.edit_profile_fragment));
Intent Intent=new Intent(getActivity(),AccountSettingsActivity.class);
putExtra(getString(R.string.calling_活动)、getString(R.string.profile_活动));
星触觉(意向);
getActivity().overridePendingTransition(R.anim.fade\u in,R.anim.fade\u out);
}
});
//TextView mFollow=(TextView)view.findViewById(R.id.tvFollowing);
msfollow.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
Intent Intent=新的Intent(getActivity(),followFragment.class);
星触觉(意向);
getActivity().overridePendingTransition(R.anim.fade\u in,R.anim.fade\u out);
}
});
返回视图;
}
@凌驾
公共void-onAttach(上下文){
试一试{
mOnGridImageSelectedListener=(OnGridImageSelectedListener)getActivity();
}catch(ClassCastException e){
Log.e(标记“onAttach:ClassCastException:”+e.getMessage());
}
super.onAttach(上下文);
}
私有void setupGridView(){
Log.d(标记“setupGridView:设置图像网格”);
最终ArrayList照片=新ArrayList();
DatabaseReference=FirebaseDatabase.getInstance().getReference();
查询=引用
.child(getString(R.string.dbname\u user\u照片))
.child(FirebaseAuth.getInstance().getCurrentUser().getUid());
query.addListenerForSingleValueEvent(新的ValueEventListener()){
@凌驾
公共void onDataChange(DataSnapshot DataSnapshot){
对于(DataSnapshot singleSnapshot:DataSnapshot.getChildren()){
照片=新照片();
MapObjectMap=(HashMap)singleSnapshot.getValue();
试一试{
setCaption(objectMap.get(getString(R.string.field_caption)).toString();
setTags(objectMap.get(getString(
public class FollowingFragment extends AppCompatActivity{

    private ArrayList<Photo> mPhotos;
    private ArrayList<Photo> mPaginatedPhotos;
    private ArrayList<String> mFollowing;
    private ListView mListView;
    private MainfeedListAdapter mAdapter;
    private int mResults;
    TextView username;
    CircleImageView profilePhoto;


    @Nullable

    public View onCreateView(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_following);
        mListView = (ListView) findViewById(R.id.listView1);
        mFollowing = new ArrayList<>();
        mPhotos = new ArrayList<>();
        getIncomingIntent();
        getFollowing();

        return mListView;
    }

    private void  getItDone(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_followrow, container, false);
        username = (TextView) view.findViewById(R.id.following_username2);
        profilePhoto = (CircleImageView) view.findViewById(R.id.following_profile_image2);}


    private void getIncomingIntent(){
        Intent intent = getIntent();



    }
    private void getFollowing(){
        Log.d(TAG, "getFollowing: searching for following");

        DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
        Query query = reference
                .child(getString(R.string.dbname_following))
                .child(FirebaseAuth.getInstance().getCurrentUser().getUid());

        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
                    Log.d(TAG, "onDataChange: found user: " +
                            singleSnapshot.child(getString(R.string.field_user_id)).getValue());


                    mFollowing.add(singleSnapshot.child(getString(R.string.field_user_id)).getValue().toString());
                    mFollowing.add(FirebaseAuth.getInstance().getCurrentUser().getUid());
                    username.setText(singleSnapshot.getValue(UserAccountSettings.class).getUsername());
                    ImageLoader imageLoader = ImageLoader.getInstance();

                    imageLoader.displayImage(
                            singleSnapshot.getValue(UserAccountSettings.class).getProfile_photo(),
                            profilePhoto);
                    }

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }




}
query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
                    Toast.makeText(this, ""+ dataSnapshot, Toast.LENGTH_SHORT).show();
                    Log.d(TAG, "onDataChange: found user: " +
                            singleSnapshot.child(getString(R.string.field_user_id)).getValue());


                    mFollowing.add(singleSnapshot.child(getString(R.string.field_user_id)).getValue().toString());
                    mFollowing.add(FirebaseAuth.getInstance().getCurrentUser().getUid());
                    username.setText(singleSnapshot.getValue(UserAccountSettings.class).getUsername());
                    ImageLoader imageLoader = ImageLoader.getInstance();

                    imageLoader.displayImage(
                            singleSnapshot.getValue(UserAccountSettings.class).getProfile_photo(),
                            profilePhoto);
                    }