Here is a little detail about my app. I have a tab layout using Fragments
and a ViewPager
. On the third tab, I have a Google Map V2. Now, whenever the user of the app would be in a certain landmark, he can share the details about that landmark on facebook. I have successfully created the map, but the details about landmarks are yet to be done. Now about the "share" function of facebook, I have followed the steps on facebook developers. When I run the app, I get the error:
10-17 14:19:06.856: E/AndroidRuntime(2180): java.lang.NullPointerException: Argument 'applicationId' cannot be null
And after searching, I found out that I need to put the application ID on the manifest.xml
.
Here is my meta-data:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="the key from google api console"
/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="the key from fb devs"
/>
However, I still get the error:
10-17 14:44:03.076: E/AndroidRuntime(2240): java.lang.NullPointerException: Argument 'applicationId' cannot be null
The whole facebook share dialog is located in a Fragment
.
Here it is:
TabFour.java
public class TabFour extends Fragment {
private UiLifecycleHelper uiHelper;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_tab_four, container, false);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("book", "https://example.com/book/Snow-Crash.html");
@SuppressWarnings("deprecation")
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "books.reads", "book")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
}
@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();
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
}
};
}
Here is my logcat.
Every project in Android includes a Manifest XML file, which is AndroidManifest. xml, located in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements.
The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
You cannot put the appID directly into the manifest itself, you need to reference a string resource in the manifest. Something like:
In your AndroidManifest:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
In your strings.xml
<resources>
...
<string name="app_id">$app_id_here</string>
</resources>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With