2

您好,我正在尝试使用 Glympse API 为 android 编写应用程序,但每次我尝试使用 createGlymspe 函数创建 Glympse 实例时都会出现此错误

 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

这是代码:

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;
    }

}

我不确定问题是否出在上下文中,但我尝试用“this”更改它,但没有帮助

4

1 回答 1

2

我能够重现该问题,并且在您的代码中没有看到任何问题,但是项目设置很可能存在问题。

首先要检查的是确保您没有将 GlympseApiLite.jar 直接放在项目的“libs”文件夹中。随着 Android Developer Tools (ADT) 17 的发布,许多 Android 开发人员开始看到此错误,因为应该导入 Android 库的方式发生了变化。

相反(如果您使用的是 Eclipse)

  1. 转到文件 -> 导入 -> Android -> 现有 Android 代码到工作区
  2. 找到 GlympseApiLite 项目 {无论您下载库的位置}/lib/GlympseApiLite。
  3. 在 Import Projects 对话框中按 Finish。

这会将 GlympseApiLite 作为项目导入。下一步是从您的项目中引用该项目。

  1. 右键单击您的项目
  2. 选择属性
  3. 在左侧列表中选择 Android
  4. 在库部分中,选择添加...
  5. 选择 GlympseApi,然后确定

让我知道这是否可以解决您的问题。请查看我们的设置文档,尤其是分步指南,以防您遇到更多麻烦。

一步一步(PDF):https ://developer.glympse.com/Content/client/lite/android/tutorials/Glympse_Api_Lite_Android_StepByStep.pdf

快速介绍(HTML):https ://developer.glympse.com/Content/client/lite/android/guides/Glympse_Api_Lite_Android_QuickIntroduction.html

编辑(回复回复):

出现错误“无法解析目标 'android-17'”是因为 GlympseApi 项目是针对该版本的 Android API 构建的。您可以编辑 GlympseAPI 的文件“project.properties”并将“target”的值更改为您已安装的版本。到目前为止,最新的是 android-18。此线程中的其他信息:无法解析目标“android-16”

对于 Jar 不匹配错误。查看其他 StackOverflow 线程: Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list

于 2013-08-21T22:10:06.783 回答