Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Argument 'context' cannot be null"

I used to have a Facebook Login button for 5 months in my application and it worked just as intended... until today. This NullPointerException came up:

java.lang.NullPointerException: Argument 'context' cannot be null
    at com.facebook.internal.Validate.notNull(Validate.java:76)
    at com.facebook.internal.Utility.getMetadataApplicationId(Utility.java:594)
    at com.facebook.appevents.AppEventsLogger.<init>(AppEventsLogger.java:757)
    at com.facebook.appevents.AppEventsLogger.<init>(AppEventsLogger.java:732)
    at com.facebook.appevents.AppEventsLogger.newLogger(AppEventsLogger.java:400)
    at com.facebook.FacebookButtonBase.logButtonCreated(FacebookButtonBase.java:225)
    at com.facebook.FacebookButtonBase.onAttachedToWindow(FacebookButtonBase.java:136)
    at com.facebook.login.widget.LoginButton.onAttachedToWindow(LoginButton.java:452)
    at android.view.View.dispatchAttachedToWindow(View.java:14514)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2843)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1364)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    at android.view.Choreographer.doFrame(Choreographer.java:606)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I suspect it's caused by the below manifest file.:

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

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />



<application

    android:allowBackup="true"
    android:icon="@mipmap/logooaca"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name=".Configs.AppController">
    <!-- Notice this tag which provides the database name -->
    <meta-data
        android:name="OACA"
        android:value="OACA.db" />
    <!-- Notice this tag which provides the database version -->
    <meta-data
        android:name="DB_VERSION"
        android:value="1" />
    <meta-data
         android:name="AA_MODELS"
         android:value="orange.oaca.model.User,orange.oaca.model.Vol,orange.oaca.model.Airport,orange.oaca.model.CategorieServiceIn" />
     <meta-data
         android:name="com.facebook.sdk.ApplicationId"
         android:value="@string/facebook_app_id" />
     <meta-data
         android:name="com.google.android.gms.version"
         android:value="@integer/google_play_services_version" />
     <meta-data
         android:name="com.google.android.geo.API_KEY"
         android:value="AIzaSyCUMuMhGrrTdt44y2XZ5hwNPO9CqeLBxSM" />
     <activity
         android:name=".SignUp"
         android:label="@string/app_name"
         android:theme="@style/AppTheme.NoActionBar" />
     <activity
         android:name=".HomeActivity"
         android:label="@string/app_name"
         android:theme="@style/AppTheme.NoActionBar" />
     <activity
         android:name="com.facebook.FacebookActivity"
         android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
         android:label="@string/app_name"
         android:theme="@android:style/Theme.Translucent.NoTitleBar" />
     <activity
         android:name=".CreerCompte"
         android:label="@string/title_activity_creer_compte"
         android:theme="@style/AppTheme.NoActionBar" />
     <activity android:name=".SplashScreen">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
     </activity>
     <activity
         android:name=".FlightListView"
         android:label="@string/title_activity_flight_list_view"
         android:theme="@style/AppTheme.NoActionBar" />
     <activity
         android:name=".AirportListView"
         android:label="@string/title_activity_airport_list_view"
         android:theme="@style/AppTheme.NoActionBar" />
     <activity
         android:name=".DetailVol"
         android:label="@string/title_activity_detail_vol"
         android:theme="@style/AppTheme.NoActionBar"></activity>
 </application>

In addition, Android Studio is making an unusual claim that there's no context: enter image description here

What's going on here?

like image 826
Ilhem Nemri Avatar asked Jun 17 '16 09:06

Ilhem Nemri


1 Answers

I got the same exception, looks like something is wrong with the new facebook SDK, I suggest to switch back to the previous version.

I changed my build.gradle

from: compile 'com.facebook.android:facebook-android-sdk:4.+
to:   compile 'com.facebook.android:facebook-android-sdk:4.12.1'

and that solved my problem.

The list of the sdk versions is here: https://developers.facebook.com/docs/android/downloads

like image 102
csursprung Avatar answered Oct 20 '22 00:10

csursprung