java.lang.ClassNotFoundException:在路径上找不到类“app path”:/data/app/
Posted
技术标签:
【中文标题】java.lang.ClassNotFoundException:在路径上找不到类“app path”:/data/app/【英文标题】:java.lang.ClassNotFoundException: Didn't find class "app path" on path: /data/app/java.lang.ClassNotFoundException:在路径上找不到类“app path”:/data/app/ 【发布时间】:2016-05-19 19:44:14 【问题描述】:我知道关于这个主题有多个问题,但我确实遵循了每一个建议的解决方案,而且我离找到适合我的正确答案还差得远。
我正在使用 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 ComponentInfoappname.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>
【问题讨论】:
也发布您的 POM。 【参考方案1】:如果没有看到 POM,我还不能完全确定,但是如果您将源代码目录结构从“appname/main/AppName.java”更改为“main/java/AppName.java”,那么您的活动就完全——合格的类名是只是 AppName
,不是 appname.main.AppName
。
【讨论】:
这是否意味着我必须将 androidManifest.xml 中的包值从 'appname.main' 更改为 'main.java'?我已经尝试过这样做,但这似乎使事情变得更糟。以上是关于java.lang.ClassNotFoundException:在路径上找不到类“app path”:/data/app/的主要内容,如果未能解决你的问题,请参考以下文章