Android Facebook SDK with fragment -
i'm trying follow facebook tutorial here https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ i'm getting error onactivityresult ideas? difference between mine , theirs mine fragment instead.
package com.projectcaruso.naturalfamilyplaning; import com.facebook.*; import com.facebook.model.*; import com.projectcaruso.naturalfamilyplanning.r; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; import android.widget.toast; import android.content.context; import android.content.intent; public class facebooklogin extends fragment{ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_login, container, false); // start facebook login session.openactivesession(getactivity(), this, true, new session.statuscallback() { // callback when session changes state @override public void call(session session, sessionstate state, exception exception) { if (session.isopened()) { // make request /me api request.executemerequestasync(session, new request.graphusercallback() { // callback after graph api response user object @override public void oncompleted(graphuser user, response response) { if (user != null) { context context = getactivity(); toast.maketext(context, "hello " + user.getname() + "!", toast.length_long).show(); } } }); } } }); return view; } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); session.getactivesession().onactivityresult(this, requestcode, resultcode, data); } }
edit: changed getactivity() this
05-14 17:10:23.904: e/androidruntime(791): fatal exception: main 05-14 17:10:23.904: e/androidruntime(791): java.lang.nullpointerexception: argument 'applicationid' cannot null 05-14 17:10:23.904: e/androidruntime(791): @ com.facebook.internal.validate.notnull(validate.java:29) 05-14 17:10:23.904: e/androidruntime(791): @ com.facebook.session.<init>(session.java:224) 05-14 17:10:23.904: e/androidruntime(791): @ com.facebook.session.<init>(session.java:213) 05-14 17:10:23.904: e/androidruntime(791): @ com.facebook.session$builder.build(session.java:1454) 05-14 17:10:23.904: e/androidruntime(791): @ com.facebook.session.openactivesession(session.java:863) 05-14 17:10:23.904: e/androidruntime(791): @ com.facebook.session.openactivesession(session.java:828) 05-14 17:10:23.904: e/androidruntime(791): @ com.projectcaruso.naturalfamilyplaning.facebookfragment.oncreateview(facebookfragment.java:29) 05-14 17:10:23.904: e/androidruntime(791): @ android.support.v4.app.fragment.performcreateview(fragment.java:1460) 05-14 17:10:23.904: e/androidruntime(791): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:911) 05-14 17:10:23.904: e/androidruntime(791): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1088) 05-14 17:10:23.904: e/androidruntime(791): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 05-14 17:10:23.904: e/androidruntime(791): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1444) 05-14 17:10:23.904: e/androidruntime(791): @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:429) 05-14 17:10:23.904: e/androidruntime(791): @ android.os.handler.handlecallback(handler.java:725) 05-14 17:10:23.904: e/androidruntime(791): @ android.os.handler.dispatchmessage(handler.java:92) 05-14 17:10:23.904: e/androidruntime(791): @ android.os.looper.loop(looper.java:137) 05-14 17:10:23.904: e/androidruntime(791): @ android.app.activitythread.main(activitythread.java:5041) 05-14 17:10:23.904: e/androidruntime(791): @ java.lang.reflect.method.invokenative(native method) 05-14 17:10:23.904: e/androidruntime(791): @ java.lang.reflect.method.invoke(method.java:511) 05-14 17:10:23.904: e/androidruntime(791): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-14 17:10:23.904: e/androidruntime(791): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-14 17:10:23.904: e/androidruntime(791): @ dalvik.system.nativestart.main(native method)
fyi in manifest , app_id in string file.
meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/app_id"
manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.projectcaruso.naturalfamilyplanning" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="14" android:targetsdkversion="17" /> <uses-permission android:name="android.permission.internet"/> <meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/app_id"/> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.projectcaruso.naturalfamilyplaning.fragmentchange" android:configchanges="orientation|screensize|screenlayout" android:theme="@style/theme.sherlock.light.darkactionbar" android:uioptions="splitactionbarwhennarrow" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.projectcaruso.naturalfamilyplaning.usersettingactivity" > </activity> <activity android:name="com.projectcaruso.naturalfamilyplaning.historyfragment" android:label="@string/title_activity_history_fragment" > </activity> </application> </manifest>
you have tag in wrong place in manifest.
it should within <application>
element have outside of element.
it should be:
<application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/app_id"/> .... </application>
Comments
Post a Comment