Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to instantiate activity java.lang.ClassNotFoundException

Tags:

android

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>
like image 931
oracleicom Avatar asked Nov 07 '12 06:11

oracleicom


4 Answers

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 !

like image 150
Regis_AG Avatar answered Oct 23 '22 17:10

Regis_AG


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.

like image 45
Sahil Mahajan Mj Avatar answered Oct 23 '22 18:10

Sahil Mahajan Mj


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

like image 1
MysticMagicϡ Avatar answered Oct 23 '22 19:10

MysticMagicϡ


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.

like image 1
Nik Reiman Avatar answered Oct 23 '22 19:10

Nik Reiman