我一直在谷歌和这个网站徘徊两个星期,以便找到我的问题的一些答案,但我没有得到任何。我已经完成了一个应用程序,用户可以在其中拍照,并希望将它们更新到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);
}
}
当我按下分享按钮时,应用程序只是崩溃..对此有所帮助将是值得欣赏的! 附:这是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
答案 0 :(得分:2)
这是因为您没有在清单中设置应用程序ID。通常情况下,如果您已经在使用其他SDK功能(例如Login),那么您已经在清单中使用它,但如果您没有,请按以下步骤添加:
在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>