java.lang.ClassNotFoundException:在路径上找不到类:dexpathlist
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22399572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassNotFoundException: Didn't find class on path: dexpathlist
提问by Karthik Sivam
I'm currently working on a project in which I have to use purely native ndk. It worked when I try running an helloworld example from Irrlicht engine source. Then I try using it in my project following the same format of that example. But I got:
我目前正在开发一个必须使用纯原生 ndk 的项目。当我尝试从 Irrlicht 引擎源运行 helloworld 示例时,它起作用了。然后我尝试按照该示例的相同格式在我的项目中使用它。但我得到了:
03-14 01:40:05.308: E/AndroidRuntime(799): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.irrlicht.example1/android.app.POMActivity}: java.lang.ClassNotFoundException: Didn't find class "android.app.POMActivity" on path: DexPathList[[zip file "/data/app/com.irrlicht.example1-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.irrlicht.example1-2, /system/lib]]
while running my project.
在运行我的项目时。
Here is my main.cpp file:
这是我的 main.cpp 文件:
#include <android/log.h>
#include <jni.h>
#include <android_native_app_glue.h>
#include "android_tools.h"
#ifdef _IRR_ANDROID_PLATFORM_
void android_main(android_app* app)
{
__android_log_print(4 , "pom" , "nothing");
}
#endif
#万一
in Android.mk:
在 Android.mk 中:
LOCAL_PATH := $(call my-dir)/..
IRRLICHT_PROJECT_PATH := $(LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := Irrlicht
LOCAL_SRC_FILES := /home/karthik/Android/Essentials/ogl-es/lib/Android/libIrrlicht.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloWorldMobile1
LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ -pipe -fno-exceptions -fno-rtti -fstrict-aliasing
LOCAL_C_INCLUDES := -I ../../include -I /home/karthik/Android/Essentials/ogl-es/include -I /home/karthik/Android/json/jsoncpp-src-0.5.0/libs/linux-gcc-4.8 -I /home/karthik/Android/json/jsoncpp-src-0.5.0/include/json
LOCAL_SRC_FILES := android_tools.cpp main.cpp
LOCAL_LDLIBS := -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid -ldl
LOCAL_STATIC_LIBRARIES := Irrlicht android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
And I have given Activity name in AndroidManifest.xml:
我在 AndroidManifest.xml 中给出了 Activity 名称:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.irrlicht.example1"
android:versionCode="1"
android:versionName="1.0">
...
<application android:icon="@drawable/irr_icon" android:label="HelloWorldMobile1" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:debuggable="true">
<activity android:name="android.app.POMActivity"
android:label="HelloWorldMobile1"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true">
<meta-data android:name="android.app.lib_name" android:value="HelloWorldMobile1" />
What is the mistake I am doing here? I'll post full code if necassary.
我在这里做的错误是什么?如果需要,我会发布完整的代码。
回答by Sushil
This seems to be problem in your case. The relative path of your activity in manifest is not correct:
在您的情况下,这似乎是问题。您的活动在清单中的相对路径不正确:
<activity android:name="android.app.POMActivity"
replace this with :
将其替换为:
<activity android:name=".POMActivity"
or
或者
<activity android:name="com.irrlicht.example1.POMActivity"
回答by mnsalim
I had a similar problem, here's my solution:
我遇到了类似的问题,这是我的解决方案:
- Right click on your project and select Properties.
- Select Java Build Pathfrom the menu on the left.
- Select the Order and Exporttab.
- From the list make sure the libraries or external jars you added to your project are checked.
- Finally, clean your project & run.
- 右键单击您的项目并选择Properties。
- 从左侧菜单中选择Java Build Path。
- 选择订购和导出选项卡。
- 从列表中确保已选中添加到项目中的库或外部 jar 。
- 最后,清理您的项目并运行。
You may also check thisanswer.
您也可以查看此答案。
回答by hemantsb
Just Change your folder name from lib
to libs
,
只需将您的文件夹名称从 更改lib
为libs
,
Then you will see some error marks in your project, to resolve this rightClick on project >
然后你会在你的项目中看到一些错误标记,解决这个问题右键单击项目>
Properties > Java Build Path > libraries
:
Properties > Java Build Path > libraries
:
Remove all the library with red marks on it, then apply > ok >
after that clean your project. TADA see the magic :)
上面有红色标记删除所有的图书馆,然后apply > ok >
,经过 清理项目。TADA 看到了魔法 :)
回答by crazyjune
- delete the bin folder
- change the order of librarys
- clean and rebuild
- 删除bin文件夹
- 更改库的顺序
- 清理和重建
worked for me.
为我工作。
回答by Ahmed Adel Ismail
after i tried the given answers, i found out another reason for the same Exception, that i had to add the library i'm using manually to my main library through
在我尝试了给定的答案后,我发现了相同异常的另一个原因,即我必须通过手动将我正在使用的库添加到我的主库中
Right click on my main library >
Properties >
Android >
Go to the very bottom of the screen and click (Add) >
Select my other library that caused the crash >
Apply
before this solution, i used the "Fix Project setup" from within the .java file in eclipse, but this did not work, so i had to add it manually here and it worked
在此解决方案之前,我使用了 Eclipse 中 .java 文件中的“修复项目设置”,但这不起作用,所以我不得不在这里手动添加它并且它起作用了
回答by Akash Bisariya
I should understand the problem by just seeing
我应该通过看到来理解问题
dex errors
dex 错误
But it took a half day to fix the issue.
I fix this by following android developers page's instruction:
https://developer.android.com/studio/build/multidex.html
但是花了半天时间才解决这个问题。
我按照android开发人员页面的说明解决了这个问题:https:
//developer.android.com/studio/build/multidex.html
First add this to gradle.build file :
首先将此添加到 gradle.build 文件:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Then extend Application class with the MultiDexApplication
class as instructed on the above link (or declare the application class in AndroidManifest.xml
or override attachBaseContext()
function if not possible to extend the application class).
然后MultiDexApplication
按照上述链接中的说明使用类扩展应用程序类(如果无法扩展应用程序类,则在AndroidManifest.xml
或覆盖attachBaseContext()
函数中声明应用程序类)。
That's all and it solved the problem.
这就是全部,它解决了问题。
回答by Vlad
The deletion of app on device and cleaning of project works for me
删除设备上的应用程序和清理项目对我有用
回答by Ali Gürelli
i solved it by using: ./gradlew --stop
command in android studio terminal. After perform this command then clean and rebuild project.
我通过使用:./gradlew --stop
android studio 终端中的命令解决了这个问题。执行此命令后,清理并重建项目。
回答by dees91
If you receive this error after removing some gradle dependency, check your manifest and make sure that you removed all entries corresponding that dependency.
如果您在删除某些 gradle 依赖项后收到此错误,请检查您的清单并确保您删除了与该依赖项对应的所有条目。
回答by Manohar Reddy
For any one who is having multidex enable write this
对于任何启用 multidex 的人,请写下这个
inside build.gradle
在build.gradle里面
apply plugin: 'com.android.application'
android {
defaultConfig {
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:multidex:1.0.1'
}
write a class EnableMultiDex
like below
写一个EnableMultiDex
像下面这样的类
import android.content.Context;
import android.support.multidex.MultiDexApplication;
public class EnableMultiDex extends MultiDexApplication {
private static EnableMultiDex enableMultiDex;
public static Context context;
public EnableMultiDex(){
enableMultiDex=this;
}
public static EnableMultiDex getEnableMultiDexApp() {
return enableMultiDex;
}
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
}
and in AndroidManifest.xml
write this classNameinside Application tag
并在Application 标签中AndroidManifest.xml
写入这个className
<application
android:name="YourPakageName.EnableMultiDex"
android:hardwareAccelerated="true"
android:icon="@drawable/wowio_launch_logo"
android:label="@string/app_name"
android:largeHeap="true"
tools:node="replace">