[英]Android: ClassNotFoundException when running ActionBarSherlock-Plugin-Maps
I am trying to setup an example project that uses Jake Wharton's ActionBarSherlock with ActionBarSherlock-Plugin-Maps . 我正在尝试设置一个使用Jake Wharton的ActionBarSherlock和ActionBarSherlock-Plugin-Maps的示例项目。 I follow the instructions here and here .
我按照这里和这里的说明进行操作。 I do not necessarily need Fragments.
我不一定需要碎片。 Here is the simple class I created.
这是我创建的简单类。
package com.example.actionbarsherlock;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockMapActivity;
public class MainActivity extends SherlockMapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
Although I tried to follow the exact descriptions I end up with a ClassNotFoundException
when I launch the application. 虽然我试图遵循确切的描述,但是当我启动应用程序时,我最终会遇到
ClassNotFoundException
。 Here is the stacktrace. 这是堆栈跟踪。
Unable to resolve superclass of Lcom/actionbarsherlock/app/SherlockMapActivity; (729)
Link of class 'Lcom/actionbarsherlock/app/SherlockMapActivity;' failed
Unable to resolve superclass of Lcom/example/actionbarsherlock/MainActivity; (533)
Link of class 'Lcom/example/actionbarsherlock/MainActivity;' failed
D/AndroidRuntime(408): Shutting down VM
threadid=3: thread exiting with uncaught exception (group=0x4001b188)
Uncaught handler: thread main exiting due to uncaught exception
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.actionbarsherlock/com.example.actionbarsherlock.MainActivity}:
java.lang.ClassNotFoundException: com.example.actionbarsherlock.MainActivity
in loader dalvik.system.PathClassLoader@44e8ca40
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.actionbarsherlock.MainActivity
in loader dalvik.system.PathClassLoader@44e8ca40
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
... 11 more
threadid=7: reacting to signal 3
Unable to open stack trace file '/data/anr/traces.txt': Permission denied
I tested the library before and created a subclass of SherlockActivity
which worked fine. 我之前测试过该库并创建了一个
SherlockActivity
的子类,它工作正常。 While doing so, I noticed that the same ClassNotFoundException
occurs when I forget to configure the android:theme
setting in AndroidManifest.xml
. 在这样做时,我注意到当我忘记在
AndroidManifest.xml
配置android:theme
设置时会发生相同的ClassNotFoundException
。 Here is the file for both ( SherlockActivity
and SherlockMapActivity
) example projects, just in case: 以下是(
SherlockActivity
和SherlockMapActivity
)示例项目的文件,以防万一:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:theme="@style/Theme.Sherlock"
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Update: 更新:
After adding the uses-library
setting as suggested by Raghav Sood and M Mohsin Naeem I run into the following message. 按照Raghav Sood和M Mohsin Naeem的建议添加
uses-library
设置后,我会遇到以下消息。
Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
Here is a screenshot of my projects' setup. 这是我项目设置的屏幕截图。
Edit: 编辑:
Maybe the .classpath
file of my actionbarsherlocktest project helps ... 也许我的actionbarsherlocktest项目的
.classpath
文件有助于......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/actionbarsherlock-plugin-maps-4.1.0.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
The .classpath
file of the library project looks exactly the same. 库项目的
.classpath
文件看起来完全相同。
Solution to the INSTALL_FAILED_MISSING_SHARED_LIBRARY
error message. INSTALL_FAILED_MISSING_SHARED_LIBRARY
错误消息的解决方案 。
For some reasons Eclipse always started the emulator that was configured for API level 7 but without the Google API . 出于某些原因,Eclipse总是启动为API级别7配置但没有Google API的模拟器。 I could not manage to force it to pick the "map-enabled" emulator.
我无法强迫它选择“启用地图”的模拟器。 After I deleted the "map-less" emulator the application launched successfully.
删除“无地图”模拟器后,应用程序成功启动。 Do you know how this can happen?
你知道这会怎么样吗?
Summary: 摘要:
Finally, I got it running. 最后,我让它运行起来。 Here are some experiences I like to share.
以下是我想分享的一些经验。
action-support-v4.jar
to the latest version. action-support-v4.jar
更新为最新版本。 actionbarsherlock-plugin-map-xyzjar
to the libs
folder of the library project. actionbarsherlock-plugin-map-xyzjar
到库项目的libs
文件夹中。 action-support-v4.jar
or the actionbarsherlock-plugin-map-xyzjar
to your main project. action-support-v4.jar
或actionbarsherlock-plugin-map-xyzjar
到您的主项目。 It is also not necessary to add any of the .jar files to the build path of the main project. There are only three reasons you will ever get this error: 您将遇到此错误的原因只有三个:
You should also add 你还应该添加
<uses-library android:name="com.google.android.maps" />
To your manifest file. 到您的清单文件。
you miss the Step 8 of this. 你错过了第8步。
<uses-library android:name="com.google.android.maps" />
you need to add this in Manifest File. 你需要在清单文件中添加它。
Make it like this 就这样吧
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:theme="@style/Theme.Sherlock"
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.