I'm trying to register using facebook ... I found an example and here I’m doing it, the only difference is that the example shows how to put the button in the fragment, and I do it without a fragment. I implemented the library, I wrote permishny, I did everything and everything loads and shows, but as soon as I insert the button in the XML file that facebook itself gives

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.stoun.life.first.facebooklogin.MainActivity" tools:showIn="@layout/app_bar_main"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> <com.facebook.login.widget.LoginButton android:id="@+id/login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="30dp" android:layout_marginBottom="30dp" /> </RelativeLayout> 

Activation code

 public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); LoginButton loginButton = (LoginButton) findViewById(R.id.login_button); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); } @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_camera) { // Handle the camera action } else if (id == R.id.nav_gallery) { } else if (id == R.id.nav_slideshow) { } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } } 

then everything crashes with an error

-03 10: 30: 25.748 30649-30649 /? I / art: Late-enabling -Xcheck: jni 05-03 10: 30: 25.788 30649-30649 /? D / TimaKeyStoreProvider: TimaSignature is unavailable 05-03 10: 30: 25.788 30649-30649 /? D / ActivityThread: Added TimaKeyStore provider 05-03 10: 30: 25.868 30649-30649 / com.stoun.life.first.facebooklogin D / ResourcesManager: creating new AssetManager and set to /data/app/com.stoun.life.first .facebooklogin-1 / base.apk 05-03 10: 30: 25.968 30649-30649 / com.stoun.life.first.facebooklogin D / KeyHash :: 1tY8plXu6Ae5AiW2u5nfNxuAkoA = 05-03 10: 30: 26.208 30649-30649 / com. stoun.life.first.facebooklogin W / art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter (android.graphics.PorterDuffColorFilter, android.content.res.Colorus, yours. .PorterDuff $ Mode) android.graphics.drawable.Drawable 05-03 10: 30: 26.248 30649-30649 / com.stoun.life.first.facebooklogin V / BitmapFactory: DecodeImagePath (decodeResourceStream3 ): res / drawable-xxhdpi-v4 / com_facebook_button_icon_blue.png 05-03 10: 30: 26.258 30649-30649 / com.stoun.life.first.facebooklogin V / BitmapFactory: DecodeImagePath (decodeResourceStream3): res / drawable-xxhdpi-v4 / com_facebook_button_icon_white.png 05-03 10: 30: 26.268 30649-30649 / com.stoun.life.first.facebooklogin D / AndroidRuntime: Shutting down VM 05 10: 30: 26.268 30649-30649 / com.stoun.life.first.facebooklogin E / AndroidRuntime: FATAL EXCEPTION: main Process: com.stoun.life.first.facebooklogin, PID: 30649 java.lang.RuntimeException: Unable to start activity ComponentInfo {com.stoun.life.first.facebooklogin / com.stoun.life.first.facebooklogin.MainActivity}: android.view.InflateException: Binary XML file line # 20: Error inflating class com.facebook.login.widget. LoginButton at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2658) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2723) at android.app.ActivityThread.access $ 900 (ActivityThread.java:172) at android. app.ActivityThread $ H.handleMessage (ActivityThread.java:1422) at android.os.Handler.dispatchMessage (Handler.java:102) at a ndroid.os.Looper.loop (Looper.java:145) at android.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (Native Method) at java.lang.reflect. Method.invoke (Method.javaUE7272) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194) Caused by: android.view.InflateException: Binary XML file line # 20: Error inflating class com.facebook.login.widget.LoginButton at android.view.LayoutInflater.createView (LayoutInflater.java:640) at android.view.LayoutInflater. createViewFromTag (LayoutInflater.java:750) at android.view.LayoutInflater.rInflate (LayoutInflater.java:813) at android.view.LayoutInflater.parseInclude (LayoutInflater.java:933) at android.view.LayoutInflater.rInrInrInrInrArntrInlterInflater.rlaf. : 809) at android.view.LayoutInflater.parseInclude (LayoutInflater.java:933) at android.view.LayoutInflater.rInflate (LayoutInflater.java:809) at android.view.LayoutInflater.inflate (LayoutIn flater.javaive11) at android.view.LayoutInflater.inflate (LayoutInflater.java:4) 15 at android.view.LayoutInflater.inflate (LayoutInflater.javaUE66) at android.support.v7.app.AppCompatDelegateImplV7.setContentView, appetheapper.eppate.v7.app. .java: 276) at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:136) at com.stoun.life.first.facebooklogin.MainActivity.onCreate (MainActivity.java:26) at android.app. Activity.performCreate (Activity.java:6221) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2611) at android.app.ActivityThread.handleLaunchActivity (ActivityThread .java: 2723) at android.app.ActivityThread.access $ 900 (ActivityThread.java:172) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1422) at android.os.Handler.dispatchMessage (Handler.java : 102) at android.os.Looper.loop (Looper.java:14 5) at android.app.ActivityThread.main (ActivityThread.java 12.83 2) at java.lang.reflect.Method.invoke (Native Method) at java.lang.reflect.Method.invoke (Method.java.0672) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit. java: 1399) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance (Native Method) at java. lang.reflect.Constructor.newInstance. .rInflate (LayoutInflater.java:813) at android.view.LayoutInflater.parseInclude (LayoutInflater.java:933) at android.view.LayoutInflater.rInflate (LayoutInflater.java:809) at android.view.LayoutInflater. java: 933) at android.view.LayoutInflater.rInflate (LayoutInflater.java:809) at android.view.LayoutInflater.inflate (LayoutInflater.java Redu11) at android.view.LayoutInfl ater. .app.AppCompatActivity.setContentView (AppCompatActivity.java:136) at com.stoun.life.first.facebooklogin.MainActivity.onCreate (MainActivity.java:26) at android.app.Activity.performCreate (Activity.java:6221) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2611) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2723) at android.app.ActivityThread .access $ 900 (ActivityThread.java:172) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1422) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:145) at android.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (Nativ e Method) at java.lang.reflect.Method.invoke (Method.javaUE72) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) at com.android.internal.os. ZygoteInit.main (ZygoteInit.java:1194) Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize () first. at com.facebook.internal.Validate.sdkInitialized (Validate.java:145) at com.facebook.AccessTokenTracker. (AccessTokenTracker.java:55) at com.facebook.login.widget.LoginButton $ 2. (LoginButton.javareek63) at com.facebook.login.widget.LoginButton.configureButton (LoginButton.javament63) at com.facebook.FacebookButtonBase. (FacebookButtonBase.java:69) at com.facebook.login.widget.LoginButton. (LoginButton.java Region01 ) at java.lang.reflect.Constructor.newInstance (Native Method) at java.lang.reflect.Constructor.newInstance (Constructor.java:288) at android.view.LayoutInflater.createView (LayoutInflater.java:614) at android. view.LayoutInflater. (LayoutInflater.java:809) at android.view.LayoutInflater.parseInclude (LayoutInflater.java:933) at android.view.LayoutInflater.rInflate (LayoutInflater.java : 809) at android.view.LayoutInflater.inflate (LayoutInflater.java sources11) at android.view.LayoutInflater.inflate (LayoutInflater.java:415) at android.view.LayoutInflater.inflate (LayoutInflater.java I66) at android .support.v7.app.AppCompatDelegateImplV7.setContentView (AppCompatDelegateImplV7.java:276) at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:136) at com.stoun.life.fust.pdf.emr.defateapproveView (AppCompatActivity.java:136) at com.stoun.life.fust.pdf.appr.AppCompatActivity.mp.AppCompatDelegateImplV7.setConv.View. (MainActivity.java:26) at android.app.Activity.performCreate (Activity.java:6221) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2611) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2723) at android.app.ActivityThread.access $ 900 (ActivityThread.java:172) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1422) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:145) at an droid.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (Native Method) at java.lang.reflect.Method.invoke (Method.java true72)

What do I need to add or change so that the error does not crash?

  • It seems that not all infa from the logs you have in the question ... And if the button is removed, then everything works? - Yuriy SPb
  • Activation code would still look - qwerty123
  • @ YuriySPb Added a full log ... Yes, if I delete the button, then everything works ... ((The most important thing is that I downloaded the example that explains it and launched it on my device and does not crash, so it’s still 2 buttons I made 1 custom, another standard one and everything works ... But he has an example with fragments ... I think it may be their business ... - Aleksey Timoshchenko
  • @ qwerty123 added full description - Aleksey Timoshchenko

1 answer 1

Found a problem! The thing was that in the video example, he explains that this line

 FacebookSdk.sdkInitialize(getApplicationContext()); 

need to write to MainActivity

But in fact, it should be described in the activation in which we get the hash key (this is another activation that we create, we make it an extend Application and we add it to the manifest file immediately after this line

 <application 

When I moved this line everything worked