简体   繁体   English

Android:运行ActionBarSherlock-Plugin-Maps时的ClassNotFoundException

[英]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的ActionBarSherlockActionBarSherlock-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: 以下是( SherlockActivitySherlockMapActivity )示例项目的文件,以防万一:

<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. 这是我项目设置的屏幕截图。

Package Explorer


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. 以下是我想分享的一些经验。

  • Download the latest version of ActionBarSherlock from the website. 从网站下载最新版本的ActionBarSherlock
  • Do not clone the repository in order to checkout the 4.1.0 tag (9598f2b). 不要克隆 ,以检出4.1.0标签(9598f2b)。 It did not work for me. 它对我不起作用。
  • Setup the ActionBarSherlock library project in Eclipse. 在Eclipse中设置ActionBarSherlock库项目。
  • Update the contained action-support-v4.jar to the latest version. 将包含的action-support-v4.jar更新为最新版本。
  • Add the actionbarsherlock-plugin-map-xyzjar to the libs folder of the library project. actionbarsherlock-plugin-map-xyzjar项目的libs文件夹中。
  • You do not need to add it to the build path of the library project. 并不需要将其添加到库项目的构建路径。
  • Setup your main project and add the library project as a dependency. 设置主项目并将库项目添加为依赖项。
  • You do not need to add the action-support-v4.jar or the actionbarsherlock-plugin-map-xyzjar to your main project. 并不需要的加action-support-v4.jaractionbarsherlock-plugin-map-xyzjar到您的主项目。 It is also not necessary to add any of the .jar files to the build path of the main project. 没有必要将任何.jar文件添加到主项目的构建路径中。
  • A simple and helpful example to follow is available in the repository. 存储库中提供了一个简单而有用的示例

There are only three reasons you will ever get this error: 您将遇到此错误的原因只有三个:

  1. The class genuinely doesn't exist. 这堂课真的不存在。 If you are using code from an official example and getting this, make sure you have the latest build of the library 如果您使用的是官方示例中的代码并获得此代码,请确保您拥有该库的最新版本
  2. You have not added the jar to your build path. 您尚未将jar添加到构建路径中。 To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path. 要解决此问题,请右键单击Eclipse中的jar,然后执行BuildPath►Addto Build Path。
  3. Your jar is not in the /libs folder. 你的jar不在/ libs文件夹中。 This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. 将jar添加到构建路径时会发生这种情况,但较新版本的ADT需要将它放在/ libs中。 Put it there and re-add it to the build path. 把它放在那里并重新添加到构建路径。

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.

相关问题 使用actionbarsherlock库的Android ClassNotFoundException - Android ClassNotFoundException using actionbarsherlock library 运行Android应用时出现ClassNotFoundException - ClassNotFoundException when running an android app Android Google Maps ClassNotFoundException - Android Google Maps ClassNotFoundException 在Genymotion模拟器上运行Google Maps API v2时发生ClassNotFoundException - ClassNotFoundException when running Google Maps API v2 on Genymotion Emulator 使用 Maven surefire 插件运行 Robolectric 测试时出现 ClassNotFoundException - Getting ClassNotFoundException when running Robolectric tests with the Maven surefire plugin Android Google Maps给出了ClassNotFoundException - Android Google Maps gives a ClassNotFoundException 带有ActionbarSherlock SearchView的ClassNotFoundException - ClassNotFoundException with ActionbarSherlock SearchView 运行Eclipse Mavenized应用程序时在Android设备上获取ClassNotFoundException - Getting ClassNotFoundException on Android device when running Eclipse mavenized app 运行应用程序时android.view.Space的ClassNotFoundException - ClassNotFoundException for android.view.Space when running application 无法从Maven添加ActionBarSherlock地图插件 - Can't add ActionBarSherlock maps plugin from Maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM