I followed the Facebook tutorial for integrating the SDK, and just after I added the Log in to Facebook button in my .xml file, my app would compile, open (on my Nexus 4 running Lollipop, project targeted to kitkat +), and then crash. I'm working on fully updated Android Studio.
Logcat:
02-07 22:48:24.340 1563-1600/com.example.prachi.mapsapplication E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.example.prachi.mapsapplication, PID: 1563
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:746)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:774)
at com.facebook.internal.Utility.queryAppSettings(Utility.java:673)
at com.facebook.widget.LoginButton$1.doInBackground(LoginButton.java:678)
at com.facebook.widget.LoginButton$1.doInBackground(LoginButton.java:675)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/main">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adventure Options"
android:id="@+id/options"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="139dp"
android:onClick="optionOnClick" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Random Adventure"
android:id="@+id/random"
android:layout_marginTop="57dp"
android:onClick="randomOnClick"
android:layout_below="@+id/authButton"
android:layout_alignStart="@+id/options" />
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
If you did not include the app id in your manifests application tag, it will crash. If that's the case, make sure your app is registered in your facebook developer account, take the app id, and put it into your string values.
<string name="app_id">XXXXXXXXXXXXXXX</string>
After that, place the following into your application tag in your manifest:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
It seems you haven't added the Facebook application id. If so you have to make app in Facebook Developers Dashboard and create a new application in the dashboard. you will get an application id. Save the application id in you values/string.xml file.
<string name="facebook_app_id">XXXXXXXXXXXXXXX</string>
and then add a meta tag to your application in AndroidManifest.xml
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With