OpenCV for Android: Sample Project ClassNotFound Exception

会有一股神秘感。 提交于 2019-12-14 03:49:19

问题


I'm trying to run a sample from opencv for android. It's not working.

 java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{org.opencv.samples.puzzle15/org.opencv.samples.
puzzle15.Puzzle15Activity}: java.lang.ClassNotFoundException: Didn't find class
"org.opencv.samples.puzzle15.Puzzle15Activity" on path:
DexPathList[[zip file "/data/app/org.opencv.samples.puzzle15-
 1.apk"],nativeLibraryDirectories=
[/data/app-lib/org.opencv.samples.puzzle15-1, /vendor/lib, /system/lib]]

What does it mean, and how do I fix it? I would like concrete steps to fix it.

Full Log:

     10-25 14:03:09.794: E/AndroidRuntime(958): FATAL EXCEPTION: main
     10-25 14:03:09.794: E/AndroidRuntime(958): java.lang.RuntimeException: Unable to     
     instantiate activity ComponentInfo{org.opencv.samples.puzzle15/
     org.opencv.samples.puzzle15.Puzzle15Activity}: java.lang.ClassNotFoundException:      
     Didn't find class "org.opencv.samples.puzzle15.Puzzle15Activity" on path:  
     /data/app/org.opencv.samples.puzzle15-2.apk
     10-25 14:03:09.794: E/AndroidRuntime(958):     at    
     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at   
     android.app.ActivityThread.access$600(ActivityThread.java:141)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     android.os.Handler.dispatchMessage(Handler.java:99)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     android.os.Looper.loop(Looper.java:137)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     android.app.ActivityThread.main(ActivityThread.java:5041)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     java.lang.reflect.Method.invokeNative(Native Method)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     java.lang.reflect.Method.invoke(Method.java:511)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at     
     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
     10-25 14:03:09.794: E/AndroidRuntime(958):     at 
     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
     10-25 14:03:09.794: E/AndroidRuntime(958): dalvik.system.NativeStart.main(NativeMethod)
     10-25 14:03:09.794: E/AndroidRuntime(958): Caused by: java.lang.ClassNotFoundException: 
     Didn't find class "org.opencv.samples.puzzle15.Puzzle15Activity" on path: 
    /data/app/org.opencv.samples.puzzle15-2.apk
    10-25 14:03:09.794: E/AndroidRuntime(958):  at 
    dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
    10-25 14:03:09.794: E/AndroidRuntime(958):  at 
    java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    10-25 14:03:09.794: E/AndroidRuntime(958):  at 
    java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    10-25 14:03:09.794: E/AndroidRuntime(958):  at 
    android.app.Instrumentation.newActivity(Instrumentation.java:1054)
    10-25 14:03:09.794: E/AndroidRuntime(958):  at 
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)

回答1:


After Importing from this OpenCV for android and download ADT Bundle

Instead of this :

   Warning : After the initial import, on a non-Windows (Linux and Mac OS) operating system Eclipse will still show build errors for applications with native C++ code. To resolve the issues, please do the following:
Open Project Properties -> C/C++ Build, and replace “Build command” text to "${NDKROOT}/ndk-build" (remove .cmd at the end).

try following steps:

Download the ndk build Android NDK

Specify the NDK location:

Windows >>> preferences >> Android >> NDK >> Set the location of the NDK (which u have downloaded from the above link)

Get location of the project :

Right Click on the project >>> properties >> resource >> location

Eg : Location : D:\OpenCV-2.4.6-android-sdk-r2\OpenCV-2.4.6-android-sdk\samples\15-puzzle

Build the project using cmd:

D:\OpenCV-2.4.6-android-sdk-r2\OpenCV-2.4.6-android-sdk\samples\15-puzzle>D:\android-ndk-r9\ndk-build

D:\android-ndk-r9\ndk-build(Your NDK path)

Note: Make sure u have included the library project and installed OpenCV Manager



来源:https://stackoverflow.com/questions/19555878/opencv-for-android-sample-project-classnotfound-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!