I had make FBLogin demo using this tutotial
Code is here
//MainActivity.java
package com.example.fbdemo;
import android.os.Bundle;
import android.app.Activity;
import com.facebook.*;
import com.facebook.model.*;
import android.widget.TextView;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// start Facebook Login
Session.openActiveSession(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 to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(R.id.welcome);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
//main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView" />
</RelativeLayout>
//AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fbdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.fbdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
</application>
</manifest>
and Error is this.
02-14 16:40:43.245: E/AndroidRuntime(6300): FATAL EXCEPTION: main
02-14 16:40:43.245: E/AndroidRuntime(6300): java.lang.NoClassDefFoundError: com.example.fbdemo.MainActivity$1
02-14 16:40:43.245: E/AndroidRuntime(6300): at com.example.fbdemo.MainActivity.onCreate(MainActivity.java:18)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.Activity.performCreate(Activity.java:4465)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.os.Looper.loop(Looper.java:137)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-14 16:40:43.245: E/AndroidRuntime(6300): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 16:40:43.245: E/AndroidRuntime(6300): at java.lang.reflect.Method.invoke(Method.java:511)
02-14 16:40:43.245: E/AndroidRuntime(6300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-14 16:40:43.245: E/AndroidRuntime(6300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-14 16:40:43.245: E/AndroidRuntime(6300): at dalvik.system.NativeStart.main(Native Method)
please give me solution.
The android:name=”.MainActivity” is not the problem. That is just a shorthand notation for what you have in your Manifest right now (meaning: the MainActivity class in the default package, which is already com.example.fbdemo).
Actually from your logging you can see that it is not MainActivity class that cannot be found, but com.example.fbdemo.MainActivity$1. The $1 means something like (give me some rope here) “the first anonymous inner class that you have in MainActivity”. From your code I think it it safe to assume that class is Session.StatusCallback() that you new in your call to Session.openActiveSession().
I don’t know this class, but is it from a library? If that is the case, are you linking the .jar file of this library in the correct way? It should be in the ‘libs’ directory of you project. In that case it should get deployed along with your app. If you just referred to it, it will only be available at compile time (hence the compiler will not complain), but Android’s packaging step will not include it in the .apk file.
Hope this helps.
[edit]Of course I may be wrong with the $1 resolving to Session.StatusCallback(). It may also be resolving to Request.GraphUserCallback(), which is another one of those “anonymous inner classes” in your code. You will have to play around a bit. Maybe it will even be both ;-)[/edit]