I seem to be having a similar problem to a myriad of the community; however, I don't seem to have the same symptoms (or at the very least, my Google-fu is not allowing me to find it).
Long story short: The app is giving me java.lang.RuntimeException: Unable to instantiate activity.
From what I understand this can only be caused by improper order of loading libraries or by missing the file in the AndroidManifest.xml.
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.alexanderlyons.livingpokedex">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is a link to my repository for those wanting to build it themselves. If anyone can give me insight as to what might be wrong.
Note: This may be due to my .gitignore, as the last time I built, it was on my main tower. I am only running into this issue on a remote machine.
TL:DR - My MainActivity is not loading, it exists in the AndriodManifest.xml, and I am only using gradles to load files, not local jars.
Your problem can be caused by different things, but the most common of it is you having too many libraries loaded, with too many methods.
You should enable multidex in your app, here's the guide:
multidex
A quick tutorial:
Add "multiDexEnabled true" to your gradle config (under target sdk version, for example).
Add this to your dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
And make sure you application extends this:
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
Either via code or via manifest.
Edit:
Test the project with the build tools 22, sd version 22 and target 22. Also, use the support libraries 22.+
Related
Im trying to add upward navigation while following the beginners tutorial to android studio here. However, when I try to run it, it gives me the error:
Error running 'app':
Default Activity not found
The code in my AndroidManifest.xml file is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
There could be a number of things going on here. I would first suggest that you check all naming references to the layout and the code behind with a discerning eye. Sometimes with editing, you can inadvertently change and rename a file by adding or deleting letter in the name. Also, from time to time, when working with a IDE, a state of modification can go stale in which you can sometimes do a clean/build or a restart of the IDE. Pending updates to the IDE may be a culprit as well.
As a best practice, you should version your code. This will help alleviate most issues such as this. Check out the following link to Android's recommendations on this practice.
https://developer.android.com/studio/publish/versioning
I am working in Android 2.3.3, and have run into this error: "Tag manifest attribute package has invalid character'_'. Initially, I was getting this error because my package name contained an underscore (com.isco_pipe.www.fieldtechapp). I have since renamed the package and removed the underscore (as you can see in the manifest file below). But the error persists upon an attempt to rebuild. Any thoughts?
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iscopipe.www.fieldtechapp">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher"
android:label="#string/app_name" android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true" android:theme="#style/AppTheme">
<activity android:name="com.iscopipe.www.fieldtechapp.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Note: I previously asked a question about not being able to debug my app on my device (running Android Studio on a virtual machine). I am now attempting to setup and run my app in Android Studio directly on my Windows laptop to see if I can run the app on an emulator and debug from there. Unable to attach debugger to Android process in Android Studio 2.3.3
Check your build.gradle file also, what you gave in applicationId.
Make sure that you are editing the proper file. Android Studio has the absolutely aggravating "feature" where certain errors cause a file in build/ to pop up in the editor. In your case, it would be a merged manifest, not your actual manifest. Editing files in build/ will have no effect, as they get re-created on each build. So, make sure that you have modified your actual manifest (e.g., src/main/AndroidManifest.xml).
I'm creating a kind of complex app that has multiple dependencies, I was using newrelic for a while with no problems, after that I wanted to add ZenDesk to the app, but when initializing the SDK , I was receiving a new relic error which was too weird! I tried for the sake of testing to remove newrelic from the app completely, so I removed compile 'com.newrelic.agent.android:android-agent:5.3.1' from the gradle file
the app doesn't work at all now! it crashes on start showing the error in the title:
java.lang.ClassNotFoundException: Didn't find class *.*.MainActivity
when I add the newrelic back the app starts to work again!
I tried to to some digging about the problem and I found few suggestions about stopping gradle and cleaning the project and so saying the problem is probably a gradle cash or so, I tried everything, I even tried it on another machine, the problem persisted !
any ideas what is wrong??
EDIT:
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:supportsRtl="true">
<activity
android:name="com.myapp.Main.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.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
</application>
</manifest>
android:name="com.myapp.Main.MainActivity"
I guess it is wrong
It will
android:name="com.orderme.MainActivity"
The ClassNotFoundException is thrown when the Java Virtual Machine
(JVM) tries to load a particular class and the specified class cannot
be found in the classpath. The ClassNotFoundException is a checked
exception and thus, must be declared in a method or constructor’s
throws clause.
What is the way
Verify that the name of the requested class is correct and that the
appropriate .jar file exists in your classpath. If not, you must
explicitly add it to your application’s classpath.
In case the specified .jar file exists in your classpath then, your
application’s classpath is getting overriden and you must find the
exact classpath used by your application.
In case the exception is caused by a third party class, you must
identify the class that throws the exception and then, add the
missing .jar files in your classpath.
Eclipse - java.lang.ClassNotFoundException
As always, the solution is 99% stupid when it comes to programming XD
at the top of my gradle file there was this:
apply plugin: 'newrelic'
I just removed this line and it works now .
I got an ClassNotFoundException with a static broadcastreceiver. The exception is fired when installing the app via eclipse on the device. I am developing an sony smartwatch extension, so I need to use the "SmartExtensionUtils" project from the sony sdk. As long as I was working inside the code example project everything was fine. I started a new project with Maven + Android and now it is no longer working!!! No idea why?!? I reckon something with the packages went wrong....
I got the following error:
E/AndroidRuntime(11201): java.lang.RuntimeException: Unable to instantiate receiver com.bla.move.smartwatch.sony.ExtensionReceiver: java.lang.ClassNotFoundException: com.bla.move.smartwatch.sony.ExtensionReceiver
My broadcastreceiver class is called ExtensionReceiver. The name inside the manifest file is the same ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bla.move.smartwatch.sony"
android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="7"/>
<uses-permission
android:name="com.sonyericsson.extras.liveware.aef.EXTENSION_PERMISSION" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="SmartWatchPreferenceActivity" android:label="#string/preference_activity_title">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name=".SmartWatchExtensionService" />
<receiver android:name=".ExtensionReceiver">
<intent-filter>
.....
</intent-filter>
</receiver>
....
What could be the problem? Any suggestions??? I did alreday clean + rebuild (a couple of times)!
Did you include the SmartExtensionAPI and SmartExtensionUtil projects as dependencies, both in your project and in Maven?
Try cleaning the workspace (start Eclipse with the -clean flag), and make sure your project's JDK compliance settings is set to 1.6 (not 1.7)! That worked for me. I set the JDK compliance level of the whole workspace, instead of the project itself, and the error just disappeared!
I've seen the following error a few times during the development cycle and now I just received an error report. I have no idea what's causing this. After reading similar questions on this site regarding this issue, I double checked my AndroidManifest and everything looks fine to me. Any ideas on what could possibly be causing this exception?
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.jerrellmardis.ridecta/com.jerrellmardis.ridecta.ui.StopTimesActivity}: java.lang.ClassNotFoundException: com.jerrellmardis.ridecta.ui.StopTimesActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.jerrellmardis.ridecta.ui.StopTimesActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
... 11 more
Another thing to note is that I'm using the android-support-v4-googlemaps lib found at https://github.com/petedoyle/android-support-v4-googlemaps which allows me to embed a MapView in a Fragment (along with the ActionBarSherlock lib). This exception seems like a dependency issue and I'm not sure if it's related to how I'm using the above mentioned libs.
Here's the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jerrellmardis.ridecta"
android:installLocation="internalOnly"
android:versionCode="11"
android:versionName="1.0.2">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.android.vending.BILLING"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name=".RideCtaApplication"
android:allowBackup="true"
android:backupAgent=".backup.RideCtaBackupAgentHelper"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/logo">
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".ui.HomeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta.LogoOnly">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".ui.BusDirectionsActivity"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta"/>
<activity
android:name=".ui.StopsActivity"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta"/>
<activity
android:name=".ui.StopTimesActivity"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta.Split"
android:uiOptions="splitActionBarWhenNarrow"/>
<activity
android:name=".ui.TrainDirectionsActivity"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta"/>
<activity
android:name=".ui.LiveMapActivity"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta.Transparent"/>
<activity
android:name=".ui.ServiceAlertsActivity"
android:label="#string/app_name"
android:theme="#style/Theme.RideCta"/>
<activity
android:name=".ui.SearchActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/Theme.RideCta">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity
android:name=".ui.PreferenceActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Preference"/>
<activity
android:name=".ui.LegacyPreferenceActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Preference"/>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<receiver android:name=".receiver.ReminderAlarmReceiver"/>
<receiver android:name=".receiver.ReminderBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name="net.robotmedia.billing.BillingReceiver">
<intent-filter>
<action android:name="com.android.vending.billing.IN_APP_NOTIFY"/>
<action android:name="com.android.vending.billing.RESPONSE_CODE"/>
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/>
</intent-filter>
</receiver>
<service android:name=".service.ReminderService"/>
<service android:name="net.robotmedia.billing.BillingService"/>
<meta-data
android:name="android.app.default_searchable"
android:value=".ui.SearchActivity"/>
<meta-data
android:name="com.google.android.backup.api_key"
android:value="<REMOVED>"/>
<provider
android:name=".provider.SearchProvider"
android:authorities="com.jerrellmardis.ridecta.provider.SearchProvider"/>
</application>
</manifest>
Right click on your project folder => Properties => Java Build Path => Order and Export => check the box "Android Private Libraries" if not checked. Make a clean. And it works !
System is not able to find your class file. So either there's something wrong with your class name specification in manifest file or your class exists in some different package as you could have specified.
Try cleaning and rebuilding your code. Some times we need to do cleaning on making updates to the code.
Also no one could find the error by just reading your logcat. so better post your manifest file and all the classes names.
Add activity to manifest file as..
<activity android:name=".FSRRemarks" >
</activity>
And if you have already added it, try to clean build your project and then run
In my experience, if you are seeing weird exceptions related to not being able to load resources or classes which you absolutely know are there, the problem could be related to pushing the activity too close to its memory limit. Having worked on a few memory-hungry apps, I can say that I've seen many exceptions reported "in the wild" having to do with not finding resources which I know were correctly included in the production build.
Generally speaking, in these cases the stacktraces never are 100% identical, so if you are consistently seeing the same missing classes, it is likely an error with your build or project configuration. Doing a full rebuild (as others have also suggested) could help.
Otherwise, I would suggest using a service like Crittercism to get more accurate information about the device right before the crashes occur.
Please follow the steps:-
1> Remove the external jars from the reference library. Don't add them here again.
2> Create another folder "libs" in your project.
3> Copy and paste your jars in the "libs" folder.
4> Clean and re-run the app.
Hope it works.
If you have already added the activity to AndroidManifest, and the activity does exist in your project, I suggest you just clean and rebuild then try again.
But I have meet another strange proble, that is apk file build by Ecplise will crash and report proble "ClassNotFoundException with applicaion", while, apk file build by ant can run normally, with no problem.
So maybe you can also try to use ant to build it, by command "android update project -p .".
To avoid errors like these, just follow these steps whenever you need to create a new class;
Double click on AndroidManifest.xml in the package explorer.
Click on the "Application" tab of the manifest editor
Click on "Add.." under the "Application Nodes" heading (bottom left
of the screen)
Choose Activity from the list in the dialog that pops up (if you
have the option, you want to create a new top-level element)
Click on the "Name*" link under the "Attributes for" header (bottom
right of the window) to create a class for the new activity.
When you click Finish from the new class dialog, it'll take you to
your new activity class so you can start coding.
Just copy your code from your activity, delete the file and recreate it like this and all your configuration related problems wil be taken care of.
Where did you copy the android-support-v4-googlemaps.jar file? inside actionbarsherlock/library/libs ? or inside your_app/libs?
Double check that you are not including two different versions of the support libraries ( one with maps and the other without them )
It looks like I've fixed the issue by not using the android-support-v4-googlemaps lib. I changed my app to use an ImageView of Map in a Fragment and then a plain old MapActivity once the user clicks on the Map image. Since doing this I haven't noticed any RuntimeExceptions.