java.lang.ClassNotFoundException:在路径上找不到类“{app path}”:/ data / app /

时间:2016-02-09 17:39:10

标签: android eclipse maven classnotfoundexception

我知道关于这个主题存在多个问题,但我确实遵循了所提出的每一个解决方案,而且我也没有找到适合我的正确答案。

我正在使用Maven成功构建.apk,但该项目不会在Eclipse中运行。

LogCat错误是:

02-09 16:54:53.040: E/AndroidRuntime(32204): FATAL EXCEPTION: main
02-09 16:54:53.040: E/AndroidRuntime(32204): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{appname.main/appname.main.AppName}: java.lang.ClassNotFoundException: Didn't find class "appname.main.AppName" on path: /data/app/appname.main-1.apk
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.os.Looper.loop(Looper.java:176)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.ActivityThread.main(ActivityThread.java:5419)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at java.lang.reflect.Method.invoke(Method.java:525)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at dalvik.system.NativeStart.main(Native Method)
02-09 16:54:53.040: E/AndroidRuntime(32204): Caused by: java.lang.ClassNotFoundException: Didn't find class "appname.main.AppName" on path: /data/app/appname.main-1.apk
02-09 16:54:53.040: E/AndroidRuntime(32204):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
02-09 16:54:53.040: E/AndroidRuntime(32204):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
02-09 16:54:53.040: E/AndroidRuntime(32204):    ... 11 more

我的androidManifest.xml是:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="appname.main"
android:versionCode="2"
android:versionName="1.01" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <activity
        android:name=".AppName"
        android:configChanges="orientation"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

      <activity
        android:name=".SplashScreen"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:configChanges="orientation"
        android:screenOrientation="portrait">
    </activity>

    <activity
        android:name="gui.SplashScreen"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:configChanges="orientation"
        android:screenOrientation="portrait">
    </activity>

</application>

我试图在三星Galaxy S3上运行它,之前一直很好地运行这个项目。

注意:自上次工作以来发生的主要变化是:转换为Maven构建 - 引用Maven依赖项 - 而不是在libs文件夹中使用预构建的jar,并更改包结构'appname.main'到'main.java'(这样Maven构建就会停止抱怨)。

如果有人能对此有所了解,我将非常感激。

编辑:现在包括pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>AppName</groupId>
  <artifactId>AppName</artifactId>
  <version>1.2.1-SNAPSHOT</version>
  <name>AppName</name>
  <packaging>apk</packaging>

  <dependencies>
  <dependency>
    <groupId>AppAndroidLibrary</groupId>
    <artifactId>AppAndroidLibrary</artifactId>
    <version>1.1</version>
  </dependency>
  <dependency>
    <groupId>AppLibrary</groupId>
    <artifactId>AppLibrary</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android</artifactId>
    <version>4.1.1.4</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
      <groupId>com.google.android</groupId>
      <artifactId>support-v4</artifactId>
      <version>r7</version>
  </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>com.simpligility.maven.plugins</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <version>4.1.1</version>
        <configuration>
          <androidManifestFile>
            ${project.basedir}/AndroidManifest.xml
              </androidManifestFile>
          <assetsDirectory>${project.basedir}/assets</assetsDirectory>
          <resourceDirectory>${project.basedir}/res</resourceDirectory>
          <sdk>
            <path>/path/to/android-sdk-macosx/</path>
            <platform>23</platform>
          </sdk>
          <proguard>
            <skip>false</skip>
          </proguard>
          <sign>
            <debug>false</debug>
          </sign>
          <deleteConflictingFiles>true</deleteConflictingFiles>
          <undeployBeforeDeploy>true</undeployBeforeDeploy>
            <excludeJarResources>
            <excludeJarResource>.*</excludeJarResource>
          </excludeJarResources>
        </configuration>
        <extensions>true</extensions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        com.simpligility.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        android-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [4.1.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>proguard</goal>
                                        <goal>emma</goal>
                                        <goal>generate-sources</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

1 个答案:

答案 0 :(得分:0)

我不能在没有看到POM的情况下告诉你,但是如果你从&#34; appname / main / AppName.java改变了源代码目录结构&#34;到&#34; main / java / AppName.java&#34;,那么您的活动的完全限定类名是只是 AppName不是 appname.main.AppName