简体   繁体   中英

Android login with facebook AppID

I'm having problems with my Android project. I'm trying to link my app to a facebook login but it gives me an error: java.Lang.NullPointerException: Argument 'applicationId' cannot be null .

It seems that the problem is on the manifest. However, my manifest is well written I believe.

I'm still learning about implementing facebook with Android so I would like some help at this point.

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.INTERNET" /> 

    <application
        android:allowBackup="true"
        android:label="Myapp"
        android:icon="@drawable/ic_launcher"
        android:theme="@android:style/Theme.NoTitleBar" >

        <activity
            android:name="myapp.screen.interfaces.Splash" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="myapp.screen.interfaces.Login" >
            <intent-filter>
                <action android:name="android.intent.action.LOGIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name="myapp.screen.interfaces.Home" >
            <intent-filter>
                <action android:name="android.intent.action.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <meta-data android:name="com.facebook.LoginActivity" android:value="@string/app_id"/>
    </application>
</manifest>

And this is my Java Code:

public class Login extends Activity {

    EditText mailIn;
    Button btSubmit;

    @Override
    protected void onCreate(Bundle tokenArg) {
        super.onCreate(tokenArg);
        setContentView(R.layout.login);

        mailIn = (EditText)findViewById(R.id.usermail);
        btSubmit = (Button)findViewById(R.id.submit);

        btSubmit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View thisView) {
                new LoginProc().execute();
            }
        });
    }

    public class LoginProc extends AsyncTask<String, Void, ArrayList<String>> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            Session.openActiveSession(Login.this, true, null);
            }

        @Override
        protected ArrayList<String> doInBackground(String... params) {
            ArrayList<String> userValues = new ArrayList<String>();

            /*  Get inputed email from the EditText field on the screen */
            userValues.add(((EditText)findViewById(R.id.usermail)).getText().toString());

            String response = new Database().login(userValues);

            if(response.toLowerCase().contains("null"))
                cancel(true);

            return (new Database().getProfile(response));
        }

        @Override
        protected void onPostExecute(ArrayList<String> result) {
            super.onPostExecute(result);

            Intent toHome = new Intent(Login.this, Home.class);
            toHome.putExtra("username", result.get(1));
            startActivity(toHome);
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            Toast.makeText(getApplicationContext(), "Not registered", Toast.LENGTH_SHORT).show();
        }
    }

What is happening? Thank you very much

You have:

<meta-data android:name="com.facebook.LoginActivity" android:value="@string/app_id"/>

But it should be:

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

Also, make sure you actually have your real app_id in your strings.xml

<resources>
  <string name="app_id">1234567890</string>
  ...
</resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM