0

我已经在谷歌和这个网站上徘徊了两个星期,以便为我的问题找到一些答案,但我没有得到任何答案。我已经做了一个应用程序,用户可以在其中拍照,并希望将它们更新到 facebook。现在,我已经设法做一个画廊,当用户按下图像时,它会在一个名为 ViewImage 的新类中打开。有一些选项菜单,例如设置和共享。现在,我希望当用户按下分享时,使用分享对话框(稍后我将尝试打开图表)将某些内容发布到他的 Facebook 个人资料中。这是 ViewImage 的代码,其中一些取自https://gist.github.com/jacklt/6700201

public class ViewImage extends Activity {
    TextView text;
    ImageView imageview;
    private int position;
    private String[] filename;
    private String[] filepath;
    private UiLifecycleHelper uiHelper;
    private static final String TAG_LOG = ViewImage.class.getSimpleName();
    private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() {
        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.d(TAG_LOG, String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.d(TAG_LOG, "Success!");
        }
    };

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (state.isOpened()) {
            Log.i(TAG_LOG, "Logged in...");
        } else if (state.isClosed()) {
            Log.i(TAG_LOG, "Logged out...");
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);

        // Get the view from view_image.xml
        setContentView(R.layout.view_image); ;

        // Retrieve data from MainActivity on GridView item click
        Intent i = getIntent();

        // Get the position
        position = i.getExtras().getInt("position");

        // Get String arrays FilePathStrings
        filepath = i.getStringArrayExtra("filepath");

        // Get String arrays FileNameStrings
        filename = i.getStringArrayExtra("filename");

        // Locate the TextView in view_image.xml
        text = (TextView) findViewById(R.id.imagetext);

        // Load the text into the TextView followed by the position
        text.setText(filename[position]);

        // Locate the ImageView in view_image.xml
        imageview = (ImageView) findViewById(R.id.full_image_view);

        imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);

        // Decode the filepath with BitmapFactory followed by the position
        Bitmap bmp = BitmapFactory.decodeFile(filepath[position]);

        bmp = GridViewAdapter.adjustImageOrientation(bmp,filepath[position]);

        // Set the decoded bitmap into ImageView
        imageview.setImageBitmap(bmp);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback);
    }

    @Override
    public void onResume() {
        super.onResume();
        uiHelper.onResume();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.view_image, menu);
        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_home) {
            {
                Intent i = new Intent();
                i.setClass(this, Main.class);
                startActivity(i);
            }
            return true;
        } else if (item.getItemId() == R.id.action_settings) {
            {
                Intent i = new Intent("net.lirazarviv.Setting");
                startActivity(i);
            }
            return true;
        } else if (item.getItemId() == R.id.action_share) {
            {
                if (FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
                    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
                            .setName("Titolo")
                            .setLink("http://developer.neosperience.com/android")
                            .setDescription("Hello from Neosperience Developer")
                            .setPicture("http://lh3.googleusercontent.com/-P4JBVTv_kSI/AAAAAAAAAAI/AAAAAAAAAAs/bZptjIhkWu4/s265-c-k-no/photo.jpg")
                            .build();
                    uiHelper.trackPendingDialogCall(shareDialog.present());

                }
                else {
                    Log.d(TAG_LOG, "Success!");
                }
            }

             return true;
        }  else return super.onOptionsItemSelected(item);
    }
}

当我按下分享按钮时,应用程序就崩溃了.. 对此的一些帮助将不胜感激!ps这里是logcat:

E/PlayerDriver(   83): PlayerDriver::handleTvOut state=[1]
10-03 15:21:45.893 E/PlayerDriver(   83): PlayerDriver::it is not a DRM file.So don't suspend TVOUT
10-03 15:21:53.440 E/AndroidRuntime( 1467): FATAL EXCEPTION: main
10-03 15:21:53.440 E/AndroidRuntime( 1467): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.lirazarviv.origame/net.lirazarviv.origame.ViewImage}: java.lang.NullPointerException: Argument 'applicationId' cannot be null
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.os.Looper.loop(Looper.java:123)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.ActivityThread.main(ActivityThread.java:3687)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at java.lang.reflect.Method.invokeNative(Native Method)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at java.lang.reflect.Method.invoke(Method.java:507)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at dalvik.system.NativeStart.main(Native Method)
10-03 15:21:53.440 E/AndroidRuntime( 1467): Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at com.facebook.internal.Validate.notNull(Validate.java:29)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at com.facebook.Session.<init>(Session.java:227)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at com.facebook.Session.<init>(Session.java:212)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at com.facebook.UiLifecycleHelper.onCreate(UiLifecycleHelper.java:87)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at net.lirazarviv.origame.ViewImage.onCreate(ViewImage.java:58)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
10-03 15:21:53.440 E/AndroidRuntime( 1467):     ... 11 more
10-03 15:21:53.748 E/        (  128): Dumpstate > /data/log/dumpstate_app_error
4

1 回答 1

2

这是因为您没有在清单中设置应用程序 ID。通常,如果您已经在使用其他 SDK 功能(例如登录),那么您应该已经在您的清单中拥有它,但如果您没有,那么添加它的方法如下:

在 AndroidManifest.xml 的应用程序标签中,添加如下内容:

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

然后,在您的 values/strings.xml 中,添加

<string name="app_id">YOUR_FACEBOOK_APP_ID</string>
于 2013-10-03T21:44:19.570 回答