使用facebook AppID登录Android

时间:2013-11-21 23:26:02

标签: java android facebook

我的Android项目出现问题。我正在尝试将我的应用程序链接到Facebook登录名,但它给了我一个错误:java.Lang.NullPointerException: Argument 'applicationId' cannot be null

似乎问题出现在清单上。但是,我相信我的清单写得很好。

我还在学习如何用Android实现facebook,所以我想在这方面提供一些帮助。

<?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>

这是我的Java代码:

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();
        }
    }

发生了什么事? 非常感谢你

1 个答案:

答案 0 :(得分:0)

你有:

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

但它应该是:

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

另外,请确保在strings.xml中确实拥有真正的app_id

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