Java – Using Facebook .jar Import error from Eclipse?

Using Facebook .jar Import error from Eclipse?… here is a solution to the problem.

Using Facebook .jar Import error from Eclipse?

When I tried to call the class UiLifecycleHelper in a plugin between Eclipse and Unity, I encountered several errors. I copied the Facebook SDK .jar under my project's libs folder and added to it

  • Properties > Java Build Path > Add JAR

I also tried to simply add “library” :

  • Properties > Android, with button Add....

No error when I don’t use class UiLifecycleHelper (Log.i works fine in testFinc, no class UiLifecycleHelper) No need to connect with Unity, with a simple class extension activity it connects nicely Facebook。

I also set the Java compiler to 1.6 as suggested in other topics.
Do you know how to properly make a connection between Facebook .jar and my project?

Here is the log:

01-05 17:17:53.834: E/dalvikvm(25005): Could not find class 'com.project.aef.MainActivity$1', referenced from method com.project.aef.MainActivity.<init>
01-05 17:17:53.835: E/dalvikvm(25005): Could not find class 'com.facebook.UiLifecycleHelper', referenced from method com.project.aef.MainActivity.onCreate
01-05 17:17:53.841: E/AndroidRuntime(25005): FATAL EXCEPTION: main
01-05 17:17:53.841: E/AndroidRuntime(25005): java.lang.NoClassDefFoundError: com.project.aef.MainActivity$1
01-05 17:17:53.841: E/AndroidRuntime(25005):    at com.project.aef.MainActivity.<init>(MainActivity.java:24)
01-05 17:17:53.841: E/AndroidRuntime(25005):    at java.lang.Class.newInstanceImpl(Native Method)
01-05 17:17:53.841: E/AndroidRuntime(25005):    at java.lang.Class.newInstance(Class.java:1319)
01-05 17:17:53.841: E/AndroidRuntime(25005):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)

Edit:
I had a similar issue on Twitter, I ended up changing the code to use Activities instead of the current code, I don’t know why the code works fine outside of the software and not when I connect to it. I also use Libgdx to make games, not Unity. The problem is solved.

Solution


Your problem is with startActivity. You have to set it up correctly. Here is an example:

public class MyActivity extends Activity {
 ...

static final int PICK_CONTACT_REQUEST = 0;

protected boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
          When the user center presses, let them pick a contact.
         startActivityForResult(
             new Intent(Intent.ACTION_PICK,
             new Uri("content://contacts")),
             PICK_CONTACT_REQUEST);
        return true;
     }
     return false;
 }

protected void onActivityResult(int requestCode, int resultCode,
         Intent data) {
     if (requestCode == PICK_CONTACT_REQUEST) {
         if (resultCode == RESULT_OK) {
              A contact was picked.  Here we will just display it
              to the user.
             startActivity(new Intent(Intent.ACTION_VIEW, data));
         }
     }
 }
}

As you can see, your code is missing “Intent”. That’s why you have this error

Related Problems and Solutions