Java LiteFactory.createGlympse()错误(Android)
您好,我正在尝试用Glympse API为android编程一个应用程序,但是每次我尝试使用createGlymspe函数创建Glympse实例时,我都会遇到这个错误Java LiteFactory.createGlympse()错误(Android),java,glympse,Java,Glympse,您好,我正在尝试用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.
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
我不确定问题是否与上下文有关,但我已尝试使用“this”来更改它,但没有帮助我能够重现该问题,并且我在您的代码中没有看到任何问题,但项目设置很可能有问题 首先要检查的是确保没有将GlympseApiLite.jar直接放在项目的“libs”文件夹中。随着Android开发者工具(ADT)17的发布,许多Android开发者开始看到这个错误,因为Android库的导入方式发生了变化 相反(如果您使用的是Eclipse)
我曾经尝试过这个方法,但是当我在eclipse工作台中导入GlympseApiLite项目时,我在控制台中遇到了这个错误:“[2013-08-22 18:44:48-GlympseApi]无法解析目标“android-17”[2013-08-22 18:44:48-GlympseApi]无法解析目标“android-17”[2013-08-22 18:45:23-Test003]在依赖项列表中找到了两个版本的android-support-v4.jar,[2013-08-22 18:45:23-Test003],但并非所有版本都相同(目前仅基于SHA-1进行检查)。[2013-08-22 18:45:23-Test003]此时库的所有版本必须相同。[2013-08-22 18:45:23-Test003]找到的版本是:[2013-08-22 18:45:23-Test003]路径:C:\Users\giole\workspace androidNew\Test003\libs\android-support-v4.jar[2013-08-22 18:45:23-Test003]长度:556198[2013-08-22 18:45:23-Test003]SHA-1:4A6BE13368BB64C5A0B0460632D228A1915F58F[2013-08-22 18:45:23-Test003]路径:C:\Android\Glympse\lib\GlympseApiLite\libs\Android-support-v4.jar[2013-08-22 18:45:23-Test003]长度:393154[2013-08-22 18:45:23-Test003]SHA-1:307C1CC532ABBF135B43E5C983C9DA700449D[2013-08-22 18:45:23-Test003]jar不匹配!修复您的依赖项对于这个混乱的答案我已经更新了您看到的其他错误的答案。
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;
}
}