简体   繁体   English

java.lang.RuntimeException:无法实例化活动ComponentInfo / ClassNotFoundException

[英]java.lang.RuntimeException: Unable to instantiate activity ComponentInfo/ ClassNotFoundException

I'm develop android application and than i wanna additional new Activity i had error on my logcat 我正在开发android应用程序,然后我想进行其他新活动,我的logcat出现错误

My LogCat: 我的LogCat:

04-19 12:59:17.654: D/AndroidRuntime(18135): Shutting down VM
04-19 12:59:17.654: W/dalvikvm(18135): threadid=1: thread exiting with uncaught exception (group=0x4001d878)
04-19 12:59:17.684: E/AndroidRuntime(18135): FATAL EXCEPTION: main
04-19 12:59:17.684: E/AndroidRuntime(18135): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.bvblogic.android.batterypower/com.bvblogic.android.batterypower.activities.UnlockActivity}: java.lang.ClassNotFoundException: com.bvblogic.android.batterypower.activities.UnlockActivity in loader dalvik.system.PathClassLoader[/data/app/com.bvblogic.android.batterypower-1.apk]
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2681)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.os.Looper.loop(Looper.java:123)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.ActivityThread.main(ActivityThread.java:4640)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at java.lang.reflect.Method.invokeNative(Native Method)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at java.lang.reflect.Method.invoke(Method.java:521)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at dalvik.system.NativeStart.main(Native Method)
04-19 12:59:17.684: E/AndroidRuntime(18135): Caused by: java.lang.ClassNotFoundException: com.bvblogic.android.batterypower.activities.UnlockActivity in loader dalvik.system.PathClassLoader[/data/app/com.bvblogic.android.batterypower-1.apk]
04-19 12:59:17.684: E/AndroidRuntime(18135):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-19 12:59:17.684: E/AndroidRuntime(18135):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2579)
04-19 12:59:17.684: E/AndroidRuntime(18135):    ... 11 more

My manifest.xml 我的manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bvblogic.android.batterypower"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BATTERY_STATS" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.HARDWARE_TEST" />
    <uses-permission android:name="android.permission.RESTART_PACKAGES" />
    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
    <uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name=".activities.UnlockActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.bvblogic.android.batterypower.activities.BatteryPowerTabActivity" >
        </activity>
        <activity android:name="com.bvblogic.android.batterypower.activities.MonitoringActivity" >
        </activity>
        <activity android:name="com.bvblogic.android.batterypower.activities.SettingsActivity" >
        </activity>
        <activity android:name="com.bvblogic.android.batterypower.activities.ProcessManagerActivity" >
        </activity>
        <activity
            android:name="com.bvblogic.android.batterypower.activities.DummyBrightnessActivity"
            android:excludeFromRecents="true"
            android:taskAffinity="com.bvblogic.android.batterypower.Dummy"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" >
        </activity>

        <service android:name="com.bvblogic.android.batterypower.util.TurboBoost" >
        </service>
        <service android:name="com.bvblogic.android.batterypower.services.BatteryPowerService" />

        <receiver
            android:name="com.bvblogic.android.batterypower.alarm.RegistrationAlarm"
            android:process=":registration" >
        </receiver>
        <receiver
            android:name="com.bvblogic.android.batterypower.alarm.OnlinePingAlarm"
            android:process=":ping" >
        </receiver>
        <receiver
            android:name="com.bvblogic.android.batterypower.alarm.AdNotificationAlarm"
            android:process=":remote" >
        </receiver>
        <receiver
            android:name="com.bvblogic.android.batterypower.widget.MWidgetProvider"
            android:icon="@drawable/btn_remove"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget_provider" />
        </receiver>
    </application>

</manifest>

My Activity: 我的活动:

package com.bvblogic.android.batterypower.activities;

import com.bvblogic.android.batterypower.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class UnlockActivity extends Activity {  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_auto_saving_layout);
    }
}

Then i'm assigned intent-filter to BatteryPowerTabActivity application started fine. 然后我被分配给Intent-filter到BatteryPowerTabActivity应用程序,启动正常。 Please help me. 请帮我。 Thanks 谢谢

When upgrading, the 'Order and Export' of the new 'Android Private Libraries' is not always checked. 升级时,不会始终检查新的“ Android私有库”的“订购和导出”。 And the android-support-v4.jar is now in this 'Android Private Libraries' section. android-support-v4.jar现在位于此“ Android私有库”部分。

To fix this, go to 'Order and Export' and check 'Android Private Libraries'. 要解决此问题,请转到“订购和导出”,然后选中“ Android私有库”。 Then refresh/clean/rebuild. 然后刷新/清理/重建。

After you done this 'fix' for a library project, you may need to just close and re-open any depending project, because they may not see this 'fix' immediately. 为库项目完成此“修复”后,您可能需要关闭并重新打开任何依赖的项目,因为他们可能不会立即看到此“修复”。

在此处输入图片说明

change your activity declaration in the manifest file into 将清单文件中的活动声明更改为

 <activity android:name=".UnlockActivity">

or else 要不然

<activity android:name="Yourcompletepackagename.UnlockActivity">

and try 并尝试

Dude, this also happened to me when my app was already published in the marketplace. 杜德(Dude),当我的应用程序已经在市场上发布时,我的情况也是如此。 It was a total disaster. 那是一场彻底的灾难。 I realized it after 5 hours of already publishing it. 我已经发布了5个小时,才意识到这一点。

There was no problem by running it with the ADT. 通过ADT运行它没有问题。 Problem was with the generated APK. 问题在于生成的APK。 So if you publish an app, test the installation of the pure APK in your test phone. 因此,如果您发布应用程序,请在测试电话中测试纯APK的安装。

As you, I also think that problem was with the the update of my ADT, in my case v22. 像您一样,我也认为问题出在我的ADT v22更新中。

The solution was to clean and build the project: 解决方案是清理并构建项目:

Android java.lang.RuntimeException: Unable to instantiate activity ComponentInfo Android java.lang.RuntimeException:无法实例化活动ComponentInfo

This can happen if your activity class is inside a default package. 如果您的活动类在默认程序包中,则可能会发生这种情况。 I fixed it by moving the activity class to a new package. 我通过将活动类移至新程序包来解决此问题。 and changing the manifest.xml 并更改manifest.xml

before 之前

activity android:name=".MainActivity" 活动android:name =“。MainActivity”

after

activity android:name="new_package.MainActivity" 活动android:name =“ new_package.MainActivity”

I had the same problem, but I had my activity declared in the Manifest file, with the correct name. 我遇到了同样的问题,但是我的活动已在清单文件中用正确的名称声明。

My problem was that I didn't have to imported a third party libraries in a "libs" folder, and I needed reference them in my proyect (Right-click, properties, Java Build Path, Libraries, Add Jar...). 我的问题是我不必在“ libs”文件夹中导入第三方库,而需要在我的proyect中引用它们(右键单击,属性,Java Build Path,库,Add Jar ...)。

About how do you declare an activity in the manifest file, is correct use .ActivityName always that activity be in the main package. 关于如何在清单文件中声明活动,正确使用.ActivityName始终使该活动位于主包中。

I agree with what @codercat has advised you to do, but this error also comes when you are using v7 and also v13 in the same project structure for different functionalities. 我同意@codercat的建议,但是当您在同一项目结构中同时使用v7和v13来实现不同功能时,也会出现此错误。 Therefore, i advice you to copy the v13 jar file into the libs folder (DO NOT import it as an external jar) and then check the android libraries and android dependencies . 因此,我建议您将v13 jar文件复制到libs文件夹中(不要将其导入为外部jar),然后检查 android库android依赖项 Refresh you project and then clean your project. 刷新您的项目,然后清理您的项目。 I am sure the error you are facing will go away. 我相信您面临的错误将会消失。

我也有同样的问题,我只是自动关闭构建并手动构建我的android项目,并清理了为我解决此错误的项目

change line from 从改变线

<activity android:name=".activities.UnlockActivity">  

to

<activity android:name=".com.bvblogic.android.batterypower.activities.UnlockActivity
 ">

Cleaning the project worked for me. 清理项目对我有用。 You might ask me what led to the issue? 您可能会问我是什么导致了这个问题? LOL I tried to upgrade a project to android 5 from 4.4 and then changed my mind and tried to restore it back to kitkat, then voila! 大声笑我试图将项目从4.4升级到android 5,然后改变了主意,试图将其还原回kitkat,然后瞧! this error came up. 这个错误出现了。

you might have declared String a = edt.getText().toString(); 您可能已经声明String a = edt.getText().toString(); or int 5/3 hence such errors use to come 或int 5/3,因此会出现此类错误

so, 所以,
declare them in onCreate method error will resolved 在onCreate方法中声明它们会解决错误

I solve this problem by remove package name( com.blogspot.geekonjava ) from AndroidManifest.xml like : 我通过从AndroidManifest.xml中删除包名称( com.blogspot.geekonjava )来解决此问题:

<activity
            android:name="com.blogspot.geekonjava.MainActivity"
            android:theme="@style/Theme.AppCompat.Light"
            android:label="@string/app_name" >

to

<activity
            android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.Light"
            android:label="@string/app_name" >

It work for me hope it works for you. 它对我有用,希望对您有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.RuntimeException:无法实例化Splash Activity的活动ComponentInfo java.lang.ClassNotFoundException - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException for Splash Activity java.lang.RuntimeException:无法实例化活动ComponentInfo {}:java.lang.ClassNotFoundException: - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{}: java.lang.ClassNotFoundException: java.lang.RuntimeException:无法实例化活动 ComponentInfo{}:java.lang.ClassNotFoundException - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{}: java.lang.ClassNotFoundException [Android Studio]java.lang.RuntimeException: 无法实例化活动 ComponentInfo java.lang.ClassNotFoundException: on path: DexPathList - [Android Studio]java.lang.RuntimeException: Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException: on path: DexPathList AndroidRuntime:java.lang.RuntimeException:无法实例化活动ComponentInfo {…/…MainActivity}:java.lang.ClassNotFoundException: - AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{…/…MainActivity}: java.lang.ClassNotFoundException: java.lang.RuntimeException:无法实例化活动ComponentInfo {...}:java.lang.ClassNotFoundException:未找到类 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{…}: java.lang.ClassNotFoundException: Didn't find class java.lang.RuntimeException:无法实例化活动ComponentInfo // java.lang.ClassNotFoundException - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo // java.lang.ClassNotFoundException java.lang.RuntimeException:无法实例化活动ComponentInfo / java.lang.ClassNotFoundException - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo / java.lang.ClassNotFoundException java.lang.RuntimeException:无法实例化活动ComponentInfo ... java.lang.ClassNotFoundException - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo … java.lang.ClassNotFoundException java.lang.RuntimeException:无法实例化活动 ComponentInfo - 不是搜索活动 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - not search activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM