java.lang.RuntimeException: Unable to instantiate activity ComponentInfo/ ClassNotFoundException
Asked Answered
A

10

14

I'm develop android application and than i wanna additional new Activity i had error on my logcat

My 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 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. Please help me. Thanks

Atticism answered 19/4, 2013 at 10:10 Comment(0)
M
19

When upgrading, the 'Order and Export' of the new 'Android Private Libraries' is not always checked. And the android-support-v4.jar is now in this 'Android Private Libraries' section.

To fix this, go to 'Order and Export' and check 'Android Private Libraries'. 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.

enter image description here

Mair answered 10/10, 2013 at 8:37 Comment(2)
For me it was in Order and Export: moving my /src and /gen to the top of the list #fmlWristlet
After getting this problem again, I think actually it was deleting my out/ dir (in my phonegap project this was in platforms/android/out/Wristlet
K
7

change your activity declaration in the manifest file into

 <activity android:name=".UnlockActivity">

or else

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

and try

Kingfisher answered 19/4, 2013 at 10:14 Comment(5)
Hi, thanks for answer. But application was crash than i'm start(Atticism
what your logcat say this timeKingfisher
make sure your all class names with the activites and services you declared in you manifestKingfisher
I address this problem 10 hours. Understand that the problem emerged after update to ADT Eclipse plugin.Atticism
All classes is declared. Problem is that i'm add new Activity (in this case UnlockActivity)Atticism
M
5

Dude, this also happened to me when my app was already published in the marketplace. It was a total disaster. I realized it after 5 hours of already publishing it.

There was no problem by running it with the ADT. Problem was with the generated APK. So if you publish an app, test the installation of the pure APK in your test phone.

As you, I also think that problem was with the the update of my ADT, in my case v22.

The solution was to clean and build the project:

Android java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

Monoplane answered 24/5, 2013 at 16:39 Comment(1)
I'm glad I found your solution - this was my situation exactly. I simply had to rebuild and recreate my .apk.Dominy
R
5

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

before

activity android:name=".MainActivity"

after

activity android:name="new_package.MainActivity"

Rang answered 7/6, 2014 at 18:13 Comment(0)
C
3

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...).

About how do you declare an activity in the manifest file, is correct use .ActivityName always that activity be in the main package.

Consuela answered 11/6, 2013 at 16:59 Comment(0)
B
1

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. 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. Refresh you project and then clean your project. I am sure the error you are facing will go away.

Bashuk answered 9/12, 2014 at 12:54 Comment(1)
Hi. In this project (that was developed a year ago) I don't used any compatibility libraries Thanks for your answer +1Atticism
R
1

i also having same problem and i just turn off build automatically and build my android project manually and cleaned my project that solved this error for me

Rexferd answered 19/12, 2014 at 11:21 Comment(1)
Hi thanks for interest solution. Many issues can be solved by clean and rebuild projectAtticism
C
0

change line from

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

to

<activity android:name=".com.bvblogic.android.batterypower.activities.UnlockActivity
 ">
Cruciferous answered 19/4, 2013 at 10:23 Comment(1)
I decided my problem. It's was simply) I'm go Project>Properties>Builders and check all checkboxes) Thanks all)Atticism
D
0

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! this error came up.

Disband answered 26/4, 2015 at 19:51 Comment(0)
M
0

you might have declared String a = edt.getText().toString(); or int 5/3 hence such errors use to come

so,
declare them in onCreate method error will resolved

Marital answered 16/5, 2015 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.