8

Ok guys this doesn't make sense to me at all and I don't understand why I am getting this error in my app. I have registered the activity class in the android manifrest xml..

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mobile.batteryhelper/com.mobile.batteryhelper.Battery}:
java.lang.ClassNotFoundException: Caused by: java.lang.ClassNotFoundException: com.mobile.batteryhelper.Battery in loader dalvik.system.PathClassLoader[/mnt/asec/com.mobile.batteryhelper-1/pkg.apk]

Here is the androidmanifest.xml. Yes the .Battery class extends Activity also.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Battery"
              android:label="@string/app_name"
               android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
3
  • <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Battery" android:label="@string/app_name" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> Commented Jun 22, 2011 at 16:11
  • user766380 If an answer solved your problem, please mark it as accepted. Commented Nov 30, 2012 at 15:58
  • For me the solutions was this: stackoverflow.com/a/21290422/1612469 Commented Oct 29, 2014 at 20:31

12 Answers 12

12

Have you tried to clean your workspace. Goto Project->Clean and select your project. For some reason eclipse doesn't build my manifest automatically.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks I guess just going into Project>Clean did the trick! Is there a reason why Eclipse sometimes doesn't build the manifest automatically?
I have no idea. Just one of its quirks i guess. I might file a bug report in the future.
6

You have put 3rd party library in library folder and reference them. Go to Properties/ Java Build Path/ Libraries/ Add External JARs.

Check the Jar files in the Properties/ Java Build Path/ Order and Export

Comments

2

Have you tried to initialise anything in your class before OnCreate gets called?
If you initialise static variables (for example) it can give you this (infuriatingly obtuse) error.

Comments

2

Actually I found my answer to this same issue here: java.lang.ClassNotFoundException on working app

You don't provide a name for the Application tag, only the Activity. So if your issue was the same as mine, you should be able to remove the following and things will work:

android:name=".Battery"

Comments

2

I had the same problem. It was a pretty confusing error until I found a way out. Go to Properties>Java Build Path>Order and Export and move your android-support-v4.jar to the top. It worked fine for me. Try it out.

Comments

1

Either your manifest package is not com.mobile.batteryhelper, or there is no com.mobile.batteryhelper.Battery class in your code. Possibly you don't have a public constructor for the class or the class is not declared public (though I think you would get a slightly different error message in that case).

Make sure that you aren't using ProGuard to strip your code. Make sure the class is public, in the correct package (same as your manifest package), and doesn't have a constructor. Also it would be useful to see the entire error stack crawl in case there is something useful inside of it.

Comments

1

Right click on your Battery class > BuildPath > Exclude Then Right click on your Battery class > BuildPath > Include your class again

Comments

1

I got this problem and fix it by moving all .jar files (external library files) which put in "lib" folder to "libs" folder. Somehow, eclipse only know .jar files put in libs folder

Comments

0

I had the same problem and I solved it by updating the ADT plugin.

Comments

0

See the crash log carefully:

loader dalvik.system.PathClassLoader[/mnt/asec/com.mobile.batteryhelper-1/pkg.apk

Here mnt means external SD card.

Normally, when android:installLocation="auto" is set in AndroidManifest.xml, if the device won't have enough phone memory, then the app will be stored on the SD card. Once you remove the SD card from the device, the app can't find the APK location, then the app crashes.

Steps to produce the crash:

Issue able to replicate in HTC sensation 2.3.4 version.

  • Move the app to SD Card by going to Settings-->Manage applications->Click on the app-->Move to SD card
  • Remove the SD card from the device and open the app

If you try with a Samsung device, it won't crash, but it won't show the app if you remove the SD Card. This behaviour is for a few devices only.

Comments

0

you can just remove the app from your mobile phone or your emulator

Comments

0

What worked for me is deleting the innermost files inside "build" folder, which are the files inside generated, intermediates, outputs, and tmp.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.