Device rebooting whenever i try to login

  android, java

Whenever i try to login/sign up on my app the device is rebooting and i get a lot of errors on the logcat but i don’t understand what that means. I have also seen something about the HomeFragment.java file in the errors but I had removed this file 3 days ago and it does not exist on my project folder anymore.

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sm.socialmeme">
    
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_logo"
        android:label="@string/app_name"
        android:roundIcon="@drawable/app_logo"
        android:supportsRtl="true"
        android:theme="@style/Theme.SocialMeme">
        <activity android:name=".UploadPhotoActivity"/>
        <activity
            android:name=".SettingsActivity"
            android:label="@string/title_activity_settings" />
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".HomeActivity" />
        <activity android:name=".SignupActivity" />
        <activity android:name=".MainActivity" />
    </application>

</manifest>

Here is some errors from the logcat:

2021-02-21 13:51:07.033 28769-28769/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sm.socialmeme, PID: 28769
    java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
        at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
        at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
        at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
        at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
        at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
        at android.view.View.performClick(View.java:7862)
        at android.view.View.performClickInternal(View.java:7831)
        at android.view.View.access$3600(View.java:879)
        at android.view.View$PerformClick.run(View.java:29359)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 13:51:19.320 31157-31157/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sm.socialmeme, PID: 31157
    java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
        at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
        at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
        at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
        at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
        at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
        at android.view.View.performClick(View.java:7862)
        at android.view.View.performClickInternal(View.java:7831)
        at android.view.View.access$3600(View.java:879)
        at android.view.View$PerformClick.run(View.java:29359)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 13:52:03.540 31590-31590/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sm.socialmeme, PID: 31590
    java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
        at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
        at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
        at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
        at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
        at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
        at android.view.View.performClick(View.java:7862)
        at android.view.View.performClickInternal(View.java:7831)
        at android.view.View.access$3600(View.java:879)
        at android.view.View$PerformClick.run(View.java:29359)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 13:54:33.531 28735-28735/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sm.socialmeme, PID: 28735
    java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.fragment.app.FragmentManager androidx.fragment.app.FragmentActivity.getSupportFragmentManager()' on a null object reference
        at com.sm.socialmeme.HomeFragment$2.onNavigationItemSelected(HomeFragment.java:132)
        at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:241)
        at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
        at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
        at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:131)
        at android.view.View.performClick(View.java:7862)
        at android.view.View.performClickInternal(View.java:7831)
        at android.view.View.access$3600(View.java:879)
        at android.view.View$PerformClick.run(View.java:29359)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 14:01:03.009 5676-5676/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sm.socialmeme, PID: 5676
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.sm.socialmeme/com.sm.socialmeme.HomeFragment}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2074)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1720)
        at android.app.Activity.startActivityForResult(Activity.java:5258)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
        at android.app.Activity.startActivityForResult(Activity.java:5203)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
        at android.app.Activity.startActivity(Activity.java:5587)
        at android.app.Activity.startActivity(Activity.java:5555)
        at com.sm.socialmeme.SplashActivity$1.run(SplashActivity.java:51)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-21 14:02:17.396 9124-9124/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sm.socialmeme, PID: 9124
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.sm.socialmeme/com.sm.socialmeme.HomeFragment}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2074)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1720)
        at android.app.Activity.startActivityForResult(Activity.java:5258)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
        at android.app.Activity.startActivityForResult(Activity.java:5203)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
        at android.app.Activity.startActivity(Activity.java:5587)
        at android.app.Activity.startActivity(Activity.java:5555)
        at com.sm.socialmeme.SplashActivity$1.run(SplashActivity.java:51)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2021-02-23 15:27:31.601 1258-1274/? E/AndroidRuntime: [email protected]*** FATAL EXCEPTION IN SYSTEM PROCESS: android.ui

MainActivity.java:

package com.sm.socialmeme;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

import org.jetbrains.annotations.NotNull;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FirebaseAuth mAuth;
        mAuth = FirebaseAuth.getInstance();
        final EditText username = findViewById(R.id.username);
        final EditText password = findViewById(R.id.password);
        final Button login_btn = findViewById(R.id.login_btn);
        final ProgressBar loading_bar = findViewById(R.id.progressBar);
        final TextView signup = findViewById(R.id.textView4);

        loading_bar.setVisibility(View.GONE);

        signup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this,SignupActivity.class));
            }
        });

        login_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loading_bar.setVisibility(View.VISIBLE);
                final String email_input = username.getText().toString();
                final String password_input = password.getText().toString();

                if (email_input.isEmpty() || password_input.isEmpty()){
                    loading_bar.setVisibility(View.GONE);
                    Toast.makeText(MainActivity.this, "All values are required", Toast.LENGTH_LONG).show();
                }else{
                    mAuth.signInWithEmailAndPassword(email_input,password_input).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull @NotNull Task<AuthResult> task) {
                            if (task.isSuccessful()){
                                finish();
                                startActivity(new Intent(MainActivity.this, HomeActivity.class));
                            }else{
                                loading_bar.setVisibility(View.GONE);
                                WrongInformationDialog dialog = new WrongInformationDialog();
                                dialog.show(getSupportFragmentManager(), "dialog");
                            
                            }
                        }
                    });
                }
            }
        });

    }
}

HomeActivity.java:

package com.sm.socialmeme;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends AppCompatActivity {


    DatabaseReference postsRef;
    DatabaseReference rootRef;
    List<PostModel> postList;
    RecyclerView.Adapter recyclerAdapter;
    RecyclerView recyclerView;
    ProgressBar progressBar;
    ImageButton like_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        final FirebaseAuth mAuth = FirebaseAuth.getInstance();
        final FirebaseUser user = mAuth.getCurrentUser();
        final BottomNavigationView bottomNavBar = findViewById(R.id.bottom_nav);
        like_btn = findViewById(R.id.likeBtn);
        recyclerView = findViewById(R.id.recyclerView);
        postsRef = FirebaseDatabase.getInstance().getReference().child("posts");
        rootRef = FirebaseDatabase.getInstance().getReference();
        progressBar = findViewById(R.id.progressBar4);
        progressBar.setVisibility(View.VISIBLE);
        postList = new ArrayList<>();

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setReverseLayout(true);
        layoutManager.setStackFromEnd(true);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(layoutManager);

        bottomNavBar.setOnNavigationItemSelectedListener(navListener);

        // keep selected fragment when rotating device 
        /*
        if (savedInstanceState == null){
            getSupportFragmentManager().beginTransaction().replace(R.id.root_container, new Fragment()).commit();
        }*/

        if (user == null) {
            finish();
            startActivity(new Intent(HomeActivity.this, MainActivity.class));
        }


            postsRef.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                        PostModel post = new PostModel();
                        post.setImgUrl(snapshot.child("imgUrl").getValue().toString());
                        post.setName(snapshot.child("name").getValue().toString());
                        post.setLikes(snapshot.child("likes").getValue().toString());
                        post.setId(snapshot.child("id").getValue().toString());

                        postList.add(post);

                        // notify adapter when a new item was added 
                        if (recyclerAdapter != null) {
                            recyclerAdapter.notifyDataSetChanged();
                        }
                    }
                    progressBar.setVisibility(View.INVISIBLE);
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {
                    Toast.makeText(HomeActivity.this, "Error: " + databaseError, Toast.LENGTH_SHORT).show();
                    progressBar.setVisibility(View.INVISIBLE);
                }
            });

            recyclerAdapter = new RecyclerAdapter(HomeActivity.this, postList);
            recyclerView.setAdapter(recyclerAdapter);
            recyclerAdapter.notifyDataSetChanged();
        }

        private BottomNavigationView.OnNavigationItemSelectedListener navListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@androidx.annotation.NonNull @NotNull MenuItem menuItem) {
                //androidx.fragment.app.Fragment selectedFragment = null;

                switch (menuItem.getItemId()){
                    case R.id.home_fragment:
                        //selectedFragment = new HomeFragment();
                        //startActivity(new Intent(HomeActivity.this, HomeActivity.class));
                        break;
                    case R.id.new_post_fragment:
                        //selectedFragment = new NewPostFragment();
                        startActivity(new Intent(getApplicationContext(), UploadPhotoActivity.class));
                        overridePendingTransition(0,0);
                        break;
                    case R.id.settings_fragment:
                        //selectedFragment = new SettingsFragment();
                        startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
                        overridePendingTransition(0,0);
                        break;
                }
                return true;
            }
        };
    }

Source: Android Questions

LEAVE A COMMENT