Error with LiteFactory.createGlympse() (Android)

282 Views Asked by At

Hello i'm tring to programm an app for android with the Glympse API but every time i try to use the createGlymspe function to create the Glympse instance i get this error

 08-21 11:10:47.014: E/AndroidRuntime(22391): FATAL EXCEPTION: main
08-21 11:10:47.014: E/AndroidRuntime(22391): java.lang.ExceptionInInitializerError
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.hal.l.<init>(ContextHolder.java:29)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.hal.bd.l(HalFactory.java:23)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.a.gz.a(LibFactory.java:35)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.api.ad.a(GlympseFactory.java:72)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.api.ad.a(GlympseFactory.java:54)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.lite.LiteFactory.createGlympse(LiteFactory.java:42)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at pcr.test02.MainActivity$1.onClick(MainActivity.java:27)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at android.view.View.performClick(View.java:3558)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at android.view.View$PerformClick.run(View.java:14157)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at android.os.Handler.handleCallback(Handler.java:605)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at android.os.Looper.loop(Looper.java:137)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at android.app.ActivityThread.main(ActivityThread.java:4514)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at java.lang.reflect.Method.invokeNative(Native Method)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at java.lang.reflect.Method.invoke(Method.java:511)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-21 11:10:47.014: E/AndroidRuntime(22391):    at dalvik.system.NativeStart.main(Native Method)
08-21 11:10:47.014: E/AndroidRuntime(22391): Caused by: java.lang.NoClassDefFoundError: com.glympse.android.api.R$drawable
08-21 11:10:47.014: E/AndroidRuntime(22391):    at com.glympse.android.hal.db.<clinit>(ResourceGateway.java:13)
08-21 11:10:47.014: E/AndroidRuntime(22391):    ... 18 more

Here is the code:

package pcr.test02;

import com.glympse.android.lite.GGlympseLite;
import com.glympse.android.lite.LiteFactory;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
    GGlympseLite glympse;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        glympse = LiteFactory.createGlympse(getBaseContext(), "sandbox.glympse.com", "I will not share my key ;-)");
        Button btn1 = (Button) findViewById(R.id.button1);
        btn1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
        Toast.makeText(getApplicationContext(), "Glymp",
        Toast.LENGTH_LONG).show();

        }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

i'm not sure if the problem is the context but i've tried to change it with "this" but it did not help

1

There are 1 best solutions below

6
On

I was able to reproduce the issue and I do not see any problems in your code, but there is very likely a problem with the project setup.

The first thing to check is to make sure you haven't put the GlympseApiLite.jar directly in your project's "libs" folder. Many Android developers started to see this error with the release of Android Developer Tools (ADT) 17 because there was a change in the way Android libraries were supposed to be imported.

Instead (if you are using Eclipse)

  1. Go to File -> Import -> Android -> Existing Android Code Into Workspace
  2. Locate GlympseApiLite project at {wherever you downloaded the library}/lib/GlympseApiLite.
  3. Press Finish in Import Projects dialog.

This will import GlympseApiLite as a project. The next step is to reference that project from your project.

  1. Right click your project
  2. Select Properties
  3. Select Android in the list at the left
  4. In the Library section, select Add...
  5. Select GlympseApi, then OK

Let me know if this fixes the issue for you. Take a look at our setup documentation especially the step by step guide in case you run into any more trouble.

Step by step (PDF): https://developer.glympse.com/Content/client/lite/android/tutorials/Glympse_Api_Lite_Android_StepByStep.pdf

Quick introduction (HTML): https://developer.glympse.com/Content/client/lite/android/guides/Glympse_Api_Lite_Android_QuickIntroduction.html

Edit (responses to replies):

The error "Unable to resolve target 'android-17'" appears because the GlympseApi Project was built against that version of the Android API. You can edit the file "project.properties" for GlympseAPI and change the value of "target" to a version that you have installed. The latest as of this moment would be android-18. Additional information in this thread: Unable to resolve target 'android-16'

For the Jar Mismatch error. See this other StackOverflow thread: Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list