0

I'm new to android development I'm doing an exercise for Facebook and Google login integration but when I added the Facebook SDK and other information in the manifest then app start crashing after splash activity I've carefully read the app id on Facebook and in the string file all are the same but I don't understand the problem please anyone help me.

This is the error message I'm getting

2020-06-05 12:08:00.132 22509-22533/com.akApplicationsInc.ToDoListApp E/GraphResponse: {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID '931273433985011' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api}
2020-06-05 12:08:02.231 22509-22509/com.akApplicationsInc.ToDoListApp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.akApplicationsInc.ToDoListApp, PID: 22509
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.akApplicationsInc.ToDoListApp/com.akApplicationsInc.ToDoListApp.LoginRegisterActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3003)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1700)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:192)
        at android.app.ActivityThread.main(ActivityThread.java:6748)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:867)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.akApplicationsInc.ToDoListApp.LoginRegisterActivity.onCreate(LoginRegisterActivity.java:32)
        at android.app.Activity.performCreate(Activity.java:7145)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2878)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3003) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1700) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:192) 
        at android.app.ActivityThread.main(ActivityThread.java:6748) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:867)  

And here is the LoginAndRegisterActivity.xml which comes after the splash screen.

 package com.akApplicationsInc.ToDoListApp;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;


import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import com.akApplicationsInc.ToDoListApp.Fragments.LoginFragment;
import com.akApplicationsInc.ToDoListApp.Fragments.RegisterFragment;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class LoginRegisterActivity extends AppCompatActivity
{

    TextView login, signup;

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

        login = findViewById(R.id.txtlogin);
        signup = findViewById(R.id.txtSingup);


        //to get the hash key

        PackageInfo info;
        try {
            info = getPackageManager().getPackageInfo("com.akApplicationsInc.ToDoListApp", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md;
                md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String something = new String(Base64.encode(md.digest(), 0));
                //String something = new String(Base64.encodeBytes(md.digest()));
                Log.e("hash key", something);
            }
        } catch (PackageManager.NameNotFoundException e1) {
            Log.e("name not found", e1.toString());
        } catch (NoSuchAlgorithmException e) {
            Log.e("no such an algorithm", e.toString());
        } catch (Exception e) {
            Log.e("exception", e.toString());
        }

        LoginFragment LogFrag = new LoginFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_view_layout, LogFrag).commit();

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginFragment LogFrag = new LoginFragment();
                getSupportFragmentManager().beginTransaction().add(R.id.fragment_view_layout, LogFrag).commit();
            }
        });

        signup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RegisterFragment RegFrag = new RegisterFragment();
                getSupportFragmentManager().beginTransaction().add(R.id.fragment_view_layout, RegFrag).commit();
            }
        });
    }
}

Here is the XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginRegisterActivity"
    android:background="@color/mattBlack"
    android:weightSum="1">


    <LinearLayout
        android:id="@+id/upper_login_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal">

    <TextView
        android:id="@+id/txtlogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LOGIN"
        android:textColor="@color/White"
        android:textSize="25sp"
        android:layout_marginTop="25dp"
        android:layout_marginLeft="40dp"
        android:fontFamily="@font/spotnik"
        android:clickable="true"/>

    <ImageView
        android:id="@+id/imagemline"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@drawable/middleline"
        android:layout_marginTop="25dp"
        android:layout_marginLeft="50dp"/>

    <TextView
        android:id="@+id/txtSingup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SIGN UP"
        android:textColor="@color/White"
        android:textSize="25sp"
        android:fontFamily="@font/spotnik"
        android:layout_marginTop="25dp"
        android:layout_marginLeft="20dp"
        android:clickable="true"/>

    </LinearLayout>

    <FrameLayout
        android:orientation="vertical"
        android:id="@+id/fragment_view_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">



    </FrameLayout>


</LinearLayout>

And i'm using two fragments for sign in and register, here are the both fragments java class.

LoginFragment.java

package com.akApplicationsInc.ToDoListApp.Fragments;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.akApplicationsInc.ToDoListApp.MainActivity;
import com.akApplicationsInc.ToDoListApp.R;
import com.google.android.material.button.MaterialButton;

import org.w3c.dom.Text;

public class LoginFragment extends Fragment implements View.OnClickListener
{

    MaterialButton btn_login, btn_fb_login, btn_google_login ;
    TextView txt_skip;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.login_fragment, container, false);


        btn_login = view.findViewById(R.id.btn_login);
        btn_fb_login = view.findViewById(R.id.btn_fb_login);
        btn_google_login = view.findViewById(R.id.btn_google_login);
        txt_skip = (TextView) view.findViewById(R.id.txt_skip);


        txt_skip.setOnClickListener(this);



        return view;
    }


    @Override
    public void onClick(View v) {

        switch(v.getId())
        {
            case R.id.txt_skip:
            {

                startActivity(new Intent(getActivity(), MainActivity.class));
            }
        }
    }
}

style.XML

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Here is the Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.akApplicationsInc.ToDoListApp">


    <uses-permission android:name="android.permission.INTERNET"/>


    <application>




    <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>



        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name=".SplashScreen"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity  android:theme="@style/Theme.AppCompat" android:name=".MainActivity"/>
        <activity android:name=".LoginRegisterActivity"/>
    </application>

</manifest>

If you need more information please let me know and make a fork and send me the solution, I would appreciate.

I'm a self-taught person so if anyone teaches me then it would be very helpful for me.

I have uploaded this project on GitHub for batter understanding please look it and give me the solution.

https://github.com/Mr-Akki-Jangir/ToDoListApp/tree/Android

Thanks.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Akki Jangir
  • 141
  • 2
  • 12

0 Answers0