簡體   English   中英

如何在Eclipse中解決android項目的ClassNotFoundException?

[英]How to solve the ClassNotFoundException of android project in eclipse?

我有一個使用Eclipse構建的android項目。 我可以構建APK,但由於以下日志而崩潰:

E/AndroidRuntime(27898): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/pili/pldroid/streaming/camera/demo/CameraStreamingActivity;
E/AndroidRuntime(27898):    at com.example.rtmpdemo.MainActivity$1.onClick(MainActivity.java:35)
E/AndroidRuntime(27898):    at android.view.View.performClick(View.java:4757)
E/AndroidRuntime(27898):    at android.view.View$PerformClick.run(View.java:19757)
E/AndroidRuntime(27898):    at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(27898):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(27898):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(27898):    at android.app.ActivityThread.main(ActivityThread.java:5258)
E/AndroidRuntime(27898):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27898):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(27898):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/AndroidRuntime(27898):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
E/AndroidRuntime(27898): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity" on path: DexPathList[[zip file "/data/app/com.example.rtmpdemo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.rtmpdemo-1/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(27898):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(27898):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(27898):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(27898):    ... 11 more
E/AndroidRuntime(27898):    Suppressed: java.lang.NoClassDefFoundError: com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity
E/AndroidRuntime(27898):        at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(27898):        at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(27898):        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(27898):        at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(27898):        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(27898):        ... 13 more
E/AndroidRuntime(27898):    Suppressed: java.lang.ClassNotFoundException: com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity
E/AndroidRuntime(27898):        at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(27898):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(27898):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(27898):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(27898):        ... 12 more
E/AndroidRuntime(27898):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
W/ActivityManager(  810):   Force finishing activity com.example.rtmpdemo/.MainActivity

我已經絕對定義了CameraStreamingActivity並在AndroidManifest.xml中進行了注冊。 該項目的結構如下:

./AndroidManifest.xml
./assets
./libs
./libs/android-support-v4.jar
./libs/armeabi-v7a
./libs/armeabi-v7a/libpldroid_ffmpegbridge.so
./libs/pldroid-camera-streaming-1.2.0.jar
./lint.xml
./proguard-project.txt
./project.properties
./src
./src/com
./src/com/example
./src/com/example/rtmpdemo
./src/com/example/rtmpdemo/MainActivity.java
./src/com/pili
./src/com/pili/pldroid
./src/com/pili/pldroid/streaming
./src/com/pili/pldroid/streaming/camera
./src/com/pili/pldroid/streaming/camera/demo
./src/com/pili/pldroid/streaming/camera/demo/AudioStreamingActivity.java
./src/com/pili/pldroid/streaming/camera/demo/CameraStreamingActivity.java
./src/com/pili/pldroid/streaming/camera/demo/StreamingBaseActivity.java
./src/com/pili/pldroid/streaming/camera/demo/TestActivity.java

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rtmpdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.rtmpdemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.pili.pldroid.streaming.camera.demo.CameraStreamingActivity" >
        </activity>
        <activity
            android:name="com.pili.pldroid.streaming.camera.demo.AudioStreamingActivity"
            android:label="@string/title_activity_audio_streaming" >
        </activity>
        <activity android:name="com.pili.pldroid.streaming.camera.demo.TestActivity" >
        </activity>
    </application>

</manifest>

但是,將項目導入Android Studio后,它運行良好。

import-summary.txt如下:

ECLIPSE ANDROID PROJECT IMPORT SUMMARY
======================================

Ignored Files:
--------------
The following files were *not* copied into the new Gradle project; you
should evaluate whether these are still needed in your project and if
so manually move them:

* .DS_Store
* ic_launcher-web.png
* proguard-project.txt

Replaced Jars with Dependencies:
--------------------------------
The importer recognized the following .jar files as third party
libraries and replaced them with Gradle dependencies instead. This has
the advantage that more explicit version information is known, and the
libraries can be updated automatically. However, it is possible that
the .jar file in your project was of an older version than the
dependency we picked, which could render the project not compileable.
You can disable the jar replacement in the import wizard and try again:

android-support-v4.jar => com.android.support:support-v4:19.1.0

Moved Files:
------------
Android Gradle projects use a different directory structure than ADT
Eclipse projects. Here's how the projects were restructured:

* AndroidManifest.xml => app/src/main/AndroidManifest.xml
* assets/ => app/src/main/assets/
* libs/armeabi-v7a/libpldroid_ffmpegbridge.so => app/src/main/jniLibs/armeabi-v7a/libpldroid_ffmpegbridge.so
* libs/pldroid-camera-streaming-1.2.0.jar => app/libs/pldroid-camera-streaming-1.2.0.jar
* lint.xml => app/lint.xml
* res/ => app/src/main/res/
* src/ => app/src/main/java/

Next Steps:
-----------
You can now build the project. The Gradle project needs network
connectivity to download dependencies.

Bugs:
-----
If for some reason your project does not build, and you determine that
it is due to a bug or limitation of the Eclipse to Gradle importer,
please file a bug at http://b.android.com with category
Component-Tools.

(This import summary is for your information only, and can be deleted
after import once you are satisfied with the results.)

我錯過了什么?

謝謝。

實際上,您的代碼沒有任何問題。 這是運行時錯誤。

我確定根本原因來自您以錯誤方式導入的庫。 “ ./libs/pldroid-camera-streaming-1.2.0.jar”嘗試刪除此lib並通過其他方式再次導入,例如:

方式1:Java構建路徑->庫->添加外部JARS。

方法2:手動將此庫直接復制到“ .libs /”文件夾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM