I was trying to run a sample code
While launching the application in the android 1.5 emulator , I got these errors....
Any one have some hint..?
ERROR from LogCat:
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): FATAL EXCEPTION: main
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.s.android.test/com.s.android.test.MainActivity}: java.lang.ClassNotFoundException: com.s.android.test.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.s.android.test-2.apk]
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1544)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.os.Looper.loop(Looper.java:123)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at java.lang.reflect.Method.invoke(Method.java:507)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at dalvik.system.NativeStart.main(Native Method)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): Caused by: java.lang.ClassNotFoundException: com.s.android.test.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.s.android.test-2.apk]
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): ... 11 more
01-13 02:28:08.407: WARN/ActivityManager(112): Force finishing activity com.s.android.test/.MainActivity
Edit
This error happens to most of the beginners, the thing is that you have to add all your activities in the Manifest file.
It is a problem of your Intent.
Please add your Activity in your AndroidManifest.xml.
When you want to make a new activity, you should register it in your AndroidManifest.xml.
You may be trying to find the view before onCreate() which is incorrect.
public class MainActivity extends Activity {
ImageView mainImage = (ImageView) findViewById(R.id.imageViewMain); //incorrect
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
...
}
There is another way to get an java.lang.RuntimeException: Unable to instantiate activity ComponentInfo exception and that is the activity that you are trying to start is abstract. I made this stupid mistake once and its very easy to overlook.
In my case I forgot to add the google maps library
<application>
....
<uses-library android:name="com.google.android.maps" />
</application>
Also, check that you're not missing the preceding dot before the activity path
<activity android:name=".activities.MainActivity"/>
It also happens because of this issue. I unchecked the jars that needed be exported to the apk and this same thing happened. Please tick the jars that your app Needs to run.
This might not be relevant to the actual question, but in my instance, I tried to implement Kotlin and left out apply plugin: 'kotlin-android'. The error happened because it could not recognize the MainActivity in as a .kt file.
Hope it helps someone.
I encountered this problem too, but in a slightly different way. Here was my scenario:
App detail:
Using ActionBarSherlock as a library
Using android-support-v4-r7-googlemaps.jar in the ActionBarSherlock library so I could use a "map fragment" in my primary project
Added the jar to the build path of my primary project
Included the <uses-library android:name="com.google.android.maps" /> in the manifests of both the library project and my primary project (this may not be necessary in the library?)
The manifest in the primary project had the proper activity definition and all of the appropriate properties
I didn't have an abstract activity or any of the other gotchas I've seen on Stack Overflow pertaining to this problem.
However, I still encountered the error described in the original post and could not get it to go away. The problem though, was slightly different in one regard:
It only affected a fresh install of the application to my device. Any time the app installed for the first time, I would get the error preceded by several "warnings" of: Unable to resolve superclass of FragmentActivity
Those warnings traced back to the ActionBarSherlock library
The app would force close and crash.
If I immediately rebuilt and redeployed the app, it worked fine.
The only time it crashed was on a totally fresh install. If I uninstalled the app, built and deployed again from Eclipse, it would crash. Build/deploy a second time, it would work fine.
How I fixed it:
In the ActionBarSherlock library project, I added the android-support-v4-r7-googlemaps.jar to the build path
This step alone did not fix the problem
Once the jar was added to the build path, I had change the order on the Java Build Path > Order and Export tab - I set the JAR to the first item in the list (it was the last after the /src and /gen items).
I then rebuilt and redeployed the app to my device - it worked as expected on a fresh install. Just to be certain, I uninstalled it again 2-3 times and reinstalled - still worked as expected.
This may be a total rookie mistake, but I spent quite a while digging through posts and my code to figure it out, so hopefully it can be helpful to someone else. May not fix all situations, but in this particular case, that ended up being the solution to my problem.
This error can also be the ultimate sign of a dumb mistake (like when I - I mean, cough, like when a friend of mine who showed me their code once) where they try to execute code outside of a method like trying to do this:
SQLiteDatabase db = openOrCreateDatabase("DB", MODE_PRIVATE, null); //trying to perform function where you can only set up objects, primitives, etc
#Override
public void onCreate(Bundle savedInstanceState) {
....
}
rather than this:
SQLiteDatabase db;
#Override
public void onCreate(Bundle savedInstanceState) {
db = openOrCreateDatabase("DB", MODE_PRIVATE, null);
....
}
For me, my package string in AndroidManifest.xml was incorrect (copied from a tutorial).
Make sure the package string in this file is the same as where your main activity is, e.g.
package="com.example.app"
An easy way to do this is to open the AndroidManifest.xml file in the "Manifest" tab, and type it in the text box next to Package, or use the Browse button.
Also, the package string for my activity was wrong, e.g.
<activity android:name="com.example.app.MainActivity" android:label="#string/app_name">
I (stupidly) got the same error weeks later when I renamed my package name. If you do this, make sure you update the AndroidManifest.xml file too.
I got rid of this problem by deleting the Bin and Gen folder from project(which automatically come back when the project will build) and then cleaning the project from ->Menu -> Project -> clean.
Thanks.
Simply Clean your working project or restart eclipse. Then run your project. it will work.
In my case I haven't set the setContentView(R.layout.main);
If you create a new class do not foget to set this in on onCreate(Bundle savedInstanceState) method.
I have done this stupid mistake several times.
For me it was different from any of the above,
The activity was declared as abstract, That is why giving the error.
Once it removed it worked.
Earlier
public abstract class SampleActivity extends AppcompatActivity{
}
After removal
public class SampleActivity extends AppcompatActivity{
}
Ok, I am fairly experienced on the iPhone but new to android. I got this issue when I had:
Button infoButton = (Button)findViewById(R.id.InfoButton);
this line of code above:
#Override
public void onCreate (Bundle savedInstanceState) {
}
May be I am sleep deprived :P
In my case, I was trying to initialize the components(UI) even before the onCreate is called for the Activity.
Make sure your UI components are initialized/linked in the onCreate method after setContentView
NB: This is my first mistake while learning Android programming.
I recently encountered this with fresh re-install of Eclipse. Turns out my Compiler compliance level was set to Java 1.7 and project required 1.6.
In Eclipse:
Project -> Properties -> Java Compiler -> JDK Compliance
Whow are there lots of ways to get this error!.
I will add another given none of the others either applied or were the cause.
I forgot the 'public' in the declaration of my activity class! It was package private.
I had been writing so much Bluetooth code that habit caused me to create an activity class that was package private.
Says something about the obscurity of this error message.
Make sure MainActivity is not "abstract".
abstract class MainActivity : AppCompatActivity()
just remove the abstract
class MainActivity : AppCompatActivity() {
Got this problem, and fixed it by setting the "launch mode" property of the activity.
Another reason of this problem may be a missing library.
Go to Properties -> Android and check that you add the libraries correctly
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...).
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"
As suggested by djjeck in comment in this answer I missed to put public modifier for my class.
It should be
public class MyActivity extends AppCompatActivity {
It may help some like me.
In my case I forget to make MainActivity class as public.
Other solutions:
Add activity in Manifest file
Verify all access modifiers
This happens to me fairly frequently when using the NDK. I found that it is necessary for me to do a "Clean" in Eclipse after every time I do a ndk-build. Hope it helps anyone :)
This error also occurs when you use of ActionBarActivity but assigned a non AppCompat style.
To fix this just set your apps style parent to an Theme.AppCompat one like this.:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
Right click on project > properties > android > and try with different version of the android earlier i was doing with android 4.4 then i changed to android 4.3 and it worked !
Most the time If Activity name changed reflected all over the project except the AndroidManifest.xml file.
You just need to Add the name in manifest manually.
<activity
android:name="Activity_Class_Name"
android:label="#string/app_name">
</activity>
I had the same issue (Unable to instantiate Activity) :
FIRST reason :
I was accessing
Camera mCamera;
Camera.Parameters params = mCamera.getParameters();
before
mCamera = Camera.open();
So right way of doing is, open the camera first and then access parameters.
SECOND reason : Declare your activity in the manifest file
<activity android:name=".activities.MainActivity"/>
THIRD reason :
Declare Camera permission in your manifest file.
<uses-feature android:name="android.hardware.Camera"></uses-feature>
<uses-permission android:name="android.permission.CAMERA" />
Hope this helps
In my case, I was trying to embed the Facebook SDK and I was having the wrong Application ID; thus the error was popping up. In your manifest file, you should have the proper meta data:
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
Related
I've tried everything I could think of, but still I cannot run my tests using Robotium.
I set the robotium library and my main project to be exported in the Project configuration as suggested here
I've set the android:debuggable flag to true as suggested here
I also checked the android:targetPackage is set properly in the manifest as suggested here
Also tried to change the scope of the main project dependency when building the test module to Provided instead of Compile (I am not sure what that does...)
Here is the AndroidManifest for the Test project:
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.matthieu.tests"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="17" />
<application
android:debuggable="true">
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.matthieu"
android:label="Tests for com.matthieu"/>
</manifest>
And here is the exception I get:
java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.reflect.InvocationTargetException
at com.matthieu.MainMenuActivityTest.<init>(MainMenuActivityTest.java:26)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4218)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.matthieu.MainMenuActivity
... 19 more
Note also that I see a few errors like this in the logcat:
01-04 14:44:51.822: WARN/dalvikvm(1263): Class resolved by unexpected DEX: Lcom/matthieu/MainMenuActivity;(0x44e7f980):0x249f70 ref [Lcom/actionbarsherlock/app/SherlockFragmentActivity;] Lcom/actionbarsherlock/app/SherlockFragmentActivity;(0x44e7f980):0x121770
01-04 14:44:51.833: WARN/dalvikvm(1263): (Lcom/matthieu/MainMenuActivity; had used a different Lcom/actionbarsherlock/app/SherlockFragmentActivity; during pre-verification)
01-04 14:44:51.851: WARN/dalvikvm(1263): Unable to resolve superclass of Lcom/matthieu/MainMenuActivity; (644)
01-04 14:44:51.851: WARN/dalvikvm(1263): Link of class 'Lcom/matthieu/MainMenuActivity;' failed
01-04 14:44:51.851: ERROR/dalvikvm(1263): Could not find class 'com.matthieu.MainMenuActivity', referenced from method com.matthieu.MainMenuActivityTest.testFirstTimeAppOpening
01-04 14:44:51.851: WARN/dalvikvm(1263): VFY: unable to resolve check-cast 849 (Lcom/matthieu/MainMenuActivity;) in Lcom/matthieu/MainMenuActivityTest;
If it makes any difference, I am using IntelliJ Idea (11.1.5), SDK 17, SDK Tools 21.0.1 and updated Robotium to 3.6
UPDATE:
Found one related discussion here. I can see different error messages whether I run only one test or all the tests, and my application does use FragmentActivity. But no matter what I do, I am not able to run any test (not one, not all)...
This type of errors occured when you did the below things.
1.If you entered wrong package name for "android:targetPackage" in manifest file.
so please check the target package name in the manifest file.
2.If you add the same library for both android app and test project.
Ambiguity occurs when you add same library for both android app and test project.so please add the library to app project only.
Finally.... I found the only way I could find to make it work there
Do not keep the Robotium test cases in a separate module... no idea why there is no way to make it work, but really I tried everything I could think of or I could find around.
I had this problem for a while and tried many things, what worked for me in the end was simply going into
properties -> Java build path -> Projects
for the test project and then removing the project under test and adding it again. (Since i cannot reproduce the problem and don't remember the details, it may be safest to remove the project under test, then clean both project, and then add the project under test)
I experienced the same problem again (see my other answer on this page) but could not solve the problem with my own solution this time. This time i found another solution: Removing the private libraries for the test project by right clicking on the test project and then
properties -> Java build path -> Libraries
and removing "Android Private Libraries"
PS My answer was inspired by information i found on this page: http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
I face same problem. its happen just because of i was trying to test my project with the JUnit instead of Android JUnit test.
so for that make test project right click on it > run as > Android Junit test.
it has work in my case.
best of luck
I am working on application which is host on android market. Sometimes (once a month ) I got a crash report:
Unable to instantiate application java.lang.ClassNotFoundException
App downloads are between 10,000-50,000. I don't know why this exceptions raise on some devices not all ( I tested it on 3 different devices & I couldn't re-produce it at my end).
I read articles/suggestions on different android forums regarding the issue but I didn't succeed in solving it. Does anyone face similar issue & suggest me what should I do?
Note:
I am extending application class like this
public class MyApplication extends Application {
}
I register it in the manifest.xml like this
<application android:icon="#drawable/app_icon"
android:label="#string/my_app_name" android:name="MyApplication">
Stack Trace :
java.lang.RuntimeException: Unable to instantiate application com.xyz.MyApplication java.lang.ClassNotFoundException: com.xyz.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.xyz-1/pkg.apk]
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:650)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4238)
at android.app.ActivityThread.access$3000(ActivityThread.java:126)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2076)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.xyz.MyApplication in loader dalvik.system.PathClassLoader[/mnt/asec/com.xyz-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newApplication(Instrumentation.java:942)
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:645)
I don't know why application crash on some devices not all.
Some other similar questions indicate that this can be a user error. "/mnt/asec/..." indicates that the app is running from the sdcard. If the sdcard is removed it could cause this error. 3rd party apps or rooted devices can probably move an app to the sdcard even if its not allowed by the manifest.
Similar Question
I think the problem is with getApplication() which I have used in 10 different place. So I have used singleton pattern to solve this.
public class MyApplication extends Application {
private static MyApplication me;
#Override
public void onCreate() {
super.onCreate();
me = this ;
}
public static MyApplication getInstance() {
return me;
}
}
Now I have used getApplication() like this
MyApplication application = MyApplication.getInstance();
insted of
MyApplication application = (MyApplication) getApplication();
I have uploaded the fixed version on the market & now waiting if there is anymore this kind of crash. If everything goes perfect ( if no more crash in 2 weeks) then I will close the question. In meanwhile anyone has better idea or know the solution , please share it. Thanks,
In my case, I was compiling and signing with Eclipse ADT (with File > Export > Export Android Application...) but missing some classes if I decompile my .apk.
To solve it I use "Export an unsigned APK" and sign it using jarsigner and zipalign.
android:name=".MyApplication"
also consider adding full package
I have a ContentProvider class and is declared in AndroidMenifest.xml like this:
<provider android:name=".MediaSearchProvider"
android:authorities="org.iii.romulus.meridian.mediasearch">
<path-permission android:path="/search_suggest_query"
android:readPermission="android.permission.GLOBAL_SEARCH" />
</provider>
It works well on most devices, but the Market tells me some users are suffering error with it. The stack trace is:
java.lang.RuntimeException: Unable to get provider org.iii.romulus.meridian.MediaSearchProvider: java.lang.ClassNotFoundException: org.iii.romulus.meridian.MediaSearchProvider in loader dalvik.system.PathClassLoader[/mnt/asec/org.iii.romulus.meridian-1/pkg.apk]
at android.app.ActivityThread.installProvider(ActivityThread.java:4509)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4281)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4237)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: org.iii.romulus.meridian.MediaSearchProvider in loader dalvik.system.PathClassLoader[/mnt/asec/org.iii.romulus.meridian-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.ActivityThread.installProvider(ActivityThread.java:4494)
... 12 more
I have totally no idea about what's up and I can't reproduce it on any of my phones. I also tried clean and build, but the report still comes up.
Anyone can help? Thanks!
The answers regarding proguard are incorrect. This would cause an easily reproducible error on every phone, every time, because the ContentProvider class would be completely missing. The developer clearly states that they cannot reproduce the error, meaning that the ContentProvider class is present but for some reason is not being found on one of their user's phones.
I have the same crash reported in the market for my app. The stack traces look identical, and the error is occurring at installProvider. I have about 15 test phones in my office and none of them can reproduce this problem. Any other ideas would be appreciated.
Fully qualified names in the manifest are only necessary if your java package names are not the same as your android package name. If a fully qualified name is not specified, the OS will automatically prepend the android package name to the class name specified in the manifest.
Ensure twice that you have correct qualified class name specified in AndroidManifest.xml, it must read something like this:
<provider
android:authorities="org.iii.romulus.meridian.mediasearch"
android:name="org.iii.romulus.meridian.MediaSearchProvider">
</provider>
Notice that #name is fully qualified.
This sounds similar to an issue I had that was caused by an issue with the ClassLoader, see here: Bizarre behaviour when using Apache Commons lib in Android
This bug discusses an error relating to the class loader failing sometimes. The fix for me was to add this line:
Thread.currentThread().setContextClassLoader(this.getClassLoader());
in the constructor of the class that was calling the code that was failing.
Proguard excludes all inherited content providers by default with this line (make sure it's in your cfg):
-keep public class * extends android.content.ContentProvider
If you have any additional inheritance you should exclude it as well or exclude your specific Content Provider class, for example:
-keep public class org.iii.romulus.meridian.MediaSearchProvider
This is an old thread, and the OP didn't have the same ContentProvider declaration as me, but I had the same exact error, so I want to share my findings, in case it helps anyone.
For me, what caused the problem was that the ContentProvider declaration in the AndroidManifest.xml had an exported attribute set to true:
android:exported="true"
Removing it fixed the problem for me. (I didn't really need it)
If your app has grown large enough to require Multidexing and your app is not set up correctly as a Multidex app you will get this error. To set up your app as a multidex app, follow these directions:
Setup multidex app
I have created and published my first Android app. It's very simple. It works fine on simulator and some phones, but I am getting this error:
java.lang.RuntimeException: Unable to instantiate application cz.teamnovak.droid.Novak ESC Track guide: java.lang.ClassNotFoundException: cz.teamnovak.droid.Novak ESC Track guide in loader dalvik.system.PathClassLoader[/data/app/cz.teamnovak.droid-1.apk]
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:649)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4232)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: cz.teamnovak.droid.Novak ESC Track guide in loader dalvik.system.PathClassLoader[/data/app/cz.teamnovak.droid-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newApplication(Instrumentation.java:942)
at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:644)
... 11 more
Any idea what can cause this?
Yep, I had this exact same problem. It was because I specified the android:name attribute in the application node in the manifest file.
Your Android Manifest file probably looks something like this:
<application
android:name="Novak ESC Track guide"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
Do not use the android:name attribute! unless you've implemented a custom Application object.
The application:name attribute has nothing to do with the name of your app. This is the name of a specific class to load as your Application instance. That's why you would get the ClassNotFoundException if that class wouldn't exist.
For the name of the app use the android:label attribute on this same application node instead.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
Something like this happened when I changed the build target to 3.2. After digging around I found that a had named the jar lib folder "lib" instead of "libs". I just renamed it to libs and updated the references on the Java build path and everything was working again. Maybe this will help someone...
We have a couple of projects where this issue was logged from time to time on the Android Market. I found the following issues in the manifests:
If the package name is com.test then activities names should be .ActivityName (with a leading dot), not just ActivityName.
For some classes, those that appeared in the logs most often, the class name was specified as com.test.Name while it should have been .Name.
I guess many implementations of Android handle these minor issues successfully (this is why the exception never happened in testing), while others few are throwing the exception.
I have this problem sometimes with eclipse. What has corrected it for me is to go to Project Properties / Android and change the build target API to a different version and republish. I'll find that corrected it, then I can change it back to the desired build target.
or
You may need to check your proguard.cfg.
Assuming you have linked your libraries properly and that your library projects have the code you need marked for export, the next step you might want to do is to check your proguard settings and make sure you are not stripping out the classes you need.
I was struggling with this quite a bit after I had my app working going directly to the emulator or device from eclipse. The problem I was having was after the app was published (i.e. gone through proguard) and run on the device it was missing classes that were contained in the project. They were being stripped out somehow.
My problem may have been caused when I had tried to use IntelliJ and have switched back to eclipse.
Here is the proguard file that worked for me:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembers class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
Had the same error: java.lang.RuntimeException: Unable to instantiate activity (classnotfound)
FIRST try to change the build platform (2.3.3 -> 2.2 -> 2.3.3) worked for me.
This is my observation with respect to the Error. I recently Updated the ADT to 22.0.1.
I am getting following Error when i imported my previous Projects
"E/AndroidRuntime(24807): Caused by: java.lang.ClassNotFoundException: com.sherl.sherlockfragmentsapp.StartActivity in loader dalvik.system.PathClassLoader[/data/app/com.sherl.sherlockfragmentsapp-1.apk]"
Then I changed "Properties->Java Build Path-> Order and Export" in the following manner
[Unable to add the Image because of the Forum rules]
Android Private Libraries - checked
Android 4.2.2 - unchecked
Android Dependencies - checked
/src - selected
/gen - selected
It resolved the issue. Hope this is Help you guys.
I know this question has been answered, and it likely wasn't the case. But I was getting this error, and figured I'd post why in case it can be helpful to anyone else.
So I was getting this error, and after several hours sheepishly realized that I had unchecked 'Project > Build Automatically'. So although I had no compilation errors, this is why I was getting this error. Everything started working as soon as I realized that I wasn't actually building the project before deploying :-/
Well, that's my story :-)
Had this sort of problem today after upgrading to latest ADT/SDK. Took me quite a while. Checked that i used google-apis (for maps), uses-library, cleaned the project etc.
Deleting the .project and adding a fresh one (create new android project) finally solved it.
I got this error when I ran my app on earlier versions of android. I thought SearchView was backwards compatible to Android 1.5, but it was created in 3.0. I removed its reference from the code and it worked.
In my case I had to add android:name=".activity.SkeletonAppActivity"
instead of android:name=".SkeletonAppActivity" in the manifest file for the main activity.
SkeletonAppActivity was in a different package from the application class. Good luck!
Make sure that android:hasCode is not set to false in your manifest file. This is what solved the problem for me!
Well you have a java.lang.ClassNotFoundException. That means a class is missing in the application runtime. You should check wheather you have added all your libs to the build path.
Right click on your project -> properties -> java build path -> libraries, add your libs or create one containing your classes and enable order export for your libs.
In my case, the icon of the app was causing the error:
<application
android:name="com.test.MyApp"
android:icon="#drawable/myicon"
Why? Because I put the icon only in the folder "drawable", and I'm using a high resolution testing device, so it looks in the folder "drawable-hdpi" for the icon. The default behaviour for everything else is use the icons from "drawable" if they aren't in "drawable-hdpi". But for the launching icon this doesn't seem to be valid.
So the solution is to put a copy of the icon (with the same name, of course) in "drawable-hdpi" (or whichever supported resolutions the devices have).
I used a supertype method that was declared 'final' in one of my Activities (specifically the 'isResumed()' method). The actual error showed in LogCat only after restarting my development device.
The Class Not Found Error shows that your class files are missing. Please go to Properties > Java Build Path and add your package containing your java files to the Source tab if found missing. Then build your project. This will create the missing .class files.
I recently invested some time in a similar error report that reached me through the play store error reports.
An overview of some possible causes.
Missing Library
Since my app is tested before release and the issue only occurs approx. once a week I'm pretty sure mine isn’t a library issue. You should think in this direction if a build on your system fails and installing the app using ADB results in error on launch.
Cleaning and building your project could help if this is a local issue and make sure you have the latest version of both SDK and IDE.
In these cases it’s one class of your app or a library used in your app that triggers the error. This is an important difference with the next point where the entry point (Activity with MAIN intent or your custom service/Application object) of your app is not found.
If so look into the following questions & answers I’ve selected. They all have an accepted answer.
unable to instantiate application - ClassNotFoundException
Android Activity ClassNotFoundException - tried everything
Android ClassNotFoundException
Main Activity or Application not found
Misconfiguration of AndroidManifest.xml
More like a beginners mistake was quoted here before in one of the answers talking about the android manifest file.
Important here is that this error would always block your app from loading. It should build though but crash on the first use.
I’ve edited that answer, this is the important part:
Do not use the android:name attribute! unless you've implemented a
custom Application object.
The application:name attribute has nothing to do with the name of your
app. This is the name of a specific class to load as your Application
instance. That's why you would get the ClassNotFoundException if that
class wouldn't exist.
For the name of the app use the android:label attribute on this same
application node instead.
Suppressed: java.io.IOException: unable to open DEX file
Now it’s getting interesting! This was part of the stack trace logged in my case through the playstore. So I can create a build and execute that on my device without errors (whereas all previous errors would prevent any run).
An important comment was made to the following SO question Android Application ClassNotFoundException, Unable to instantiate application
Looks like the system has trouble opening your application dex file java.io.IOException: unable to open DEX file, this is before any of your classes are loaded, so it doesn't have anything to do with how you define your application class in the Manifest. – user2046264 Feb 27 '14 at 2:25
The important part here is the suppressed IOException. This indicates that an IO operation failed. Examples of IO operations are network and storage calls.
Another error report that goes into that direction is listed at Android to Unable to instantiate Application java.lang.ClassNotFoundException: where the role of the external storage provided by an sdcard is mentioned.
Some other similar questions indicate that this can be a user error. "/mnt/asec/..." indicates that the app is running from the sdcard. If the sdcard is removed it could cause this error. 3rd party apps or rooted devices can probably move an app to the sdcard even if its not allowed by the manifest.
If you’re desperate read all the answers to that question since there are some other paths listed also. Think of full package specification, use of singletons and more.
The point here is that both network and storage are IO.
For my specific case I checked all the devices that reported this error and found that they all have external storage support. So a user could install the app and move it to external storage, have the SD card removed and get this error (just a theory, not tested).
For more info on the installLocation options see http://developer.android.com/guide/topics/data/install-location.html
I also considered the network. On top of the stack trace detail page at the play store reports you get an overview of the occurrences of the error over time.
It appeared to me that the error occurred more around the times an update was released. This could support the theory that the user gets an update of the app, downloads this update that somehow gets corrupted. The installation goes fine but the first execution of the app results in the error (again just a theory, not tested).
Other resources
Finally 2 non SO resources that might help you:
https://groups.google.com/forum/#!topic/android-developers/JC7_qqwBRjo
https://code.google.com/p/android/issues/detail?id=72121
Are you using your code in different enviroments, let's say, by using Dropbox or something like that? Do you use any library or similar? I had a lot of troubles after sharing the workspace files and I fixed it reconfiguring dependences. Hope it helps somebody!
Check if the package name in the class matches the package name in the manifest file. This worked for me
In my case it happen when i moved my launcher activity to different package without updating manifest file.
I had a ClassNotFoundException pointing to my Application class.
I found that I missed Java builder in my .project
If something is missing in your buildSpec, close Eclipse, make sure everything is in place and start Eclipse again
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
I have same problem in android os version 4.1.2
add below line to your AndroidManifest.xml below android:label="#string/app_name" in application tag
android:name="android.support.multidex.MultiDexApplication"
This may help some one with same problem.
Setting minifyEnabled to false in my build.gradle file fixed the issue for me.
release {
minifyEnabled false
}
For me it was just to clean project.
I cleaned project, and run again. And all errors gone.
What helped me in case of Android Studio:
The problem occurred after renamning package of large project.
So I did almost everything AS offers to clean and refresh the project officially, and it works. I'm not saying this is solution for everyone just in case you're using Android Studio. Done in Android Studio 3.5.1, Windows 10.
Alex's answer
Build > Clean Project
Build > Rebuild Project
File > Sync with File System
File > Sync project with Gradle Files
File > Invalidate Caches / Restart
Make sure that you have package
com.aaraf.demowithdoc //Your Package Name
com.aaraf.demowithdoc [YOUR PACKAGE NAME]
is there in your class where this java.lang.classnotfoundexception is occuring
For me, 'closing' the application from Eclipse and 'reopening' of the project, resolved the issue.
When I start my (soon-to-be) android game (from eclipse) it opens, but immediately force-closes.
Logcat says:
07-09 17:12:35.709: ERROR/AndroidRuntime(3866): Uncaught handler: thread main exiting due to uncaught exception
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.anselm.eickhoff.rhythm/org.anselm.eickhoff.rhythm.RhythmGameActivity}: java.lang.ClassNotFoundException: org.anselm.eickhoff.rhythm.RhythmGameActivity in loader dalvik.system.PathClassLoader#4001e740
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2497)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.os.Looper.loop(Looper.java:123)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.reflect.Method.invoke(Method.java:521)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at dalvik.system.NativeStart.main(Native Method)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): Caused by: java.lang.ClassNotFoundException: org.anselm.eickhoff.rhythm.RhythmGameActivity in loader dalvik.system.PathClassLoader#4001e740
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2489)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): ... 11 more
the interesting line here is (I think):
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): Caused by: java.lang.ClassNotFoundException: org.anselm.eickhoff.rhythm.RhythmGameActivity in loader dalvik.system.PathClassLoader#4001e740
Which surprises me, because I have this class (in the right package)
edit: to clarify, added the first line which I had omitted (together with the imports)
package org.anselm.eickhoff.rhythm;
...
public class RhythmGameActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public void onPause() {
}
}
and that's all it does!
I also registered it in the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.anselm.eickhoff.rhythm"
android:versionCode="1" android:versionName="pre-alpha">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true" android:hasCode="false">
<activity android:name=".RhythmGameActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
edit: this all has started since I renamed the activity from RhythmGame to RhythmGameActivity, but I am pretty sure I replaced all the references so maybe it is still wrongly chached somewhere? (I tried refreshing and cleaning the project)
Your help is really appreciated - im stuck!
I use Perforce with Eclipse and have discovered that Perforce's default behavior of making all files under source control read-only causes build problems that aren't clearly specified in Eclipse's build window. Also, there seems to be a quirk for me when adding a library project where even if the .classpath and .project file are writable the library may not properly associate itself with the project. I generally follow these steps for resolving errors of this nature (this assumes that the project's manifest is correct):
1) Close Eclipse. Eclipse may cache some info about a file's R/W status.
2) (Broad stroke) Make all of the files in the project writable either by checking them out from source control, or through the OS. .classpath and .project at the bare minimum should be writable.
2.5) If you placed files under source control that are generated during the build process and are a normal part of the Android build process then they should be removed from source control and made writable. Including but not limited to .class and files in the bin and gen directories.
3) Open the project in Eclipse. If there are no errors the problem may be fixed.
4) Examine the project explorer and look specifically for library project dependencies that may be missing. In my experience it's important to see all lib projects' directories and their library status icon in your project's explorer hierarchy. If a lib project folder and icon is missing, go to Properties->Android and select and add the missing lib(s). After adding a lib select "Apply" an watch the project explorer to make sure that the lib icon appears in the project directory. This step explanation may seem overly detailed, but I've been bitten several times before forcing myself to be extra observant here. If a lib won't add, try adding other dummy lib project and removing them in combination with the lib you want. No joke - this is sometimes necessary for me.
5) Clean all of the projects.
6) Read the error list and resolve any other errors.
7) Fix all of the warnings you've been putting off fixing.
8) (Not essential but important) Revert all unchanged files and observe what's left in you changelist - these are the files that will need your attention in the future to prevent build problems.
Just had the same problem. After updating ADT to the newest version, my lib folder was no longer recognized. Had to rename it to libs Now: do they really have to release new SDK every 5 minutes? Can't they create ONE stable environment for some longer time?
I had this problem once when my working application suddenly started throwing ClassNotFoundException. The problem was that the classes were not being compiled and translated to the "dex" file, this is obvious to find because the APK just shrinks.
So, in eclipse, in order to fix it just add the javabuilder to your .project file.
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
Hope it helps.
Try to fix .classpath.
Had the same problem caused by corrupt .classpath file. After fixing it the ClassNotFoundException was gone.
The background is that we are using SVN, an update caused a conflict in .classpath. Eclipse, however, did not show any error message or hint about that. I only found out when I tried to submit the current changes.
The solution here was to do a fresh SVN check out of the project, so a working version of .classpath was restored.
Not really a solution but this fixed it:
creating a new project from scratch and migrating the code
Please close this if something like it is possible here.
Thanks for all your ideas and thoughts!
Just had this same problem. Was going nuts. Fully restarted emulator/adb/and eclipse and it fixed it. Strange stuff...
Did you rename in Eclipse. Double check that it renamed with sub-package correctly. In my case it removed the dot:
Wrong: ui.MyActivity
Fix: .ui.MyActivity
I had the same problem and in my case, I had forgot to put a library in the Android Manifest. I had a MapView Activity and I had forgot to put :
<uses-library android:name="com.google.android.maps"/>.
So, you should make sure you have all your library included in your manifest.
I got this error in a FragmentActivity after updating the SDK to Android 4. The reason was, that you no longer need to include the android-support-v4.jar. Just add the support tools by clicking right mouse button on your Project, than Android Tools -> Add support library.
I know it's not your problem , but I had exactly the same problem. Suddenly my app stopped working. I didint make any change to manifest, but with some accident there was missing first row:
<?xml version="1.0" encoding="utf-8"?>
This caused ClassNotFoundException for launcher activity. I was struggling with that for few hours and I overlooked this every time I was checking manifest for possible mistake.
Strange thing happened after I have deleted this row again. Suprise, suprise app was still working. (and I didnt forget to rebuild app)
Hope this help someone to save few hours.
Perhaps your run configuration refers to the old name. Click on the little triangle next to the green run button, and select Run Configurations. Make sure the one for this project refers to the right activity name. Or just delete it and Eclipse will automatically make you a new one.