5

我正在尝试将 Facebook 集成到我的应用程序中。但是一旦我点击fbphoto它就会抛出错误android.content.res.Resources$NotFoundException。我确实知道它会引发错误,因为在运行时没有建立适当的资源。

发现错误是在facebook.authorize(this, new String[] { "email", "publish_stream"}, new DialogListener() {}. 但根本原因仍然缺失。

fbphoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            loginToFacebook();
        }
    });

public void loginToFacebook()
{
if(!facebook.isSessionValid())
    {
        facebook.authorize(this, new String[] { "email", "publish_stream"}, new DialogListener() {

        });
    }

02-08 02:57:58.236: E/AndroidRuntime(1582): FATAL EXCEPTION: main
02-08 02:57:58.236: E/AndroidRuntime(1582): android.content.res.Resources$NotFoundException: String resource ID #0x7f050011
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.content.res.Resources.getText(Resources.java:201)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.content.res.Resources.getString(Resources.java:254)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.content.Context.getString(Context.java:183)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.widget.WebDialog.onCreate(WebDialog.java:188)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.app.Dialog.show(Dialog.java:225)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.AuthorizationClient$WebViewAuthHandler.tryAuthorize(AuthorizationClient.java:462)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:210)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:189)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:117)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:98)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.Session.tryLegacyAuth(Session.java:1096)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.Session.authorize(Session.java:893)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.Session.open(Session.java:957)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.Session.openForPublish(Session.java:415)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.android.Facebook.openSession(Facebook.java:319)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.android.Facebook.authorize(Facebook.java:313)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.facebook.android.Facebook.authorize(Facebook.java:149)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.example.splashscreen.SecondScreen.loginToFacebook(SecondScreen.java:110)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.example.splashscreen.SecondScreen$1.onClick(SecondScreen.java:73)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.view.View.performClick(View.java:2485)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.view.View$PerformClick.run(View.java:9080)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.os.Handler.handleCallback(Handler.java:587)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.os.Looper.loop(Looper.java:123)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at android.app.ActivityThread.main(ActivityThread.java:3683)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at java.lang.reflect.Method.invokeNative(Native Method)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at java.lang.reflect.Method.invoke(Method.java:507)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-08 02:57:58.236: E/AndroidRuntime(1582):     at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

8

请注意,如果您正在运行 IntelliJ 并将 Facebook 源代码作为库模块包含在您的项目中,也会发生此错误。

目前还不清楚究竟是什么导致了这种情况发生,但是当 Facebook 项目(整个树)作为库模块包含在 IntelliJ 项目中时,facebook strings.xml 文件有时会被一个非常简单的 strings.xml 文件覆盖,并中断Facebook 登录屏幕上出现 Resources Not Found 异常的应用。不仅如此,Facebook AndroidManifest 有时也会被覆盖并导致编译时问题。

替换伪造的 strings.xml 和 AndroidManifest.xml 文件将解决此问题。

于 2013-06-14T06:31:06.677 回答
4

从堆栈跟踪,错误是由这一行引起的:

spinner.setMessage(getContext().getString(R.string.com_facebook_loading));

源代码在这里

资源在res/values/string.xml中正确定义

显然,错误不在 facebook-android-sdk 中。

我猜你的项目设置有问题。您可以按照本指南正确设置您的项目。

于 2013-02-07T21:53:45.950 回答