0

I am getting the following error:

java.lang.ClassCastException: com.example.cillin.map.AuthenticationApplication cannot be cast to com.example.cillin.map.NBHAuthenticationApplication

This is the line where the error is marked:

NBHAuthenticationApplication myNBHApp = (NBHAuthenticationApplication) getApplication();

This is the class which that line is in:

import android.app.Activity;
import android.os.Bundle;

public class NBHBaseActivity extends Activity
{
    protected NBHAuthService mNBHAuthService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        NBHAuthenticationApplication myNBHApp = (NBHAuthenticationApplication) getApplication();
        myNBHApp.setCurrentNBHActivity(this);
        mNBHAuthService = myNBHApp.getNBHAuthService();
    }
}

And this is the NBHAuthenticationApplication class:

public class NBHAuthenticationApplication extends Application
{
    private NBHAuthService mNBHAuthService;
    private Activity mCurrentNBHActivity;

    public NBHAuthenticationApplication() {}

    public NBHAuthService getNBHAuthService() {
        if (mNBHAuthService == null) {
            mNBHAuthService = new NBHAuthService(this);
        }
        return mNBHAuthService;
    }

    public void setCurrentNBHActivity(Activity NBHactivity) {
        mCurrentNBHActivity = NBHactivity;
    }

    public Activity getCurrentActivity() {
        return mCurrentNBHActivity;
    }
}

Any ideas as to why this error is occuring? I have added the file to my manifest file as suggested in similar questions with this error but still no luck..

Manifest:

<application
        android:largeHeap="true"
        android:name="AuthenticationApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >


        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" >

        </activity>
        <activity
            android:name=".MainMenu"
            android:label="@string/MainMenu" >

        </activity>
        <activity
            android:name=".CrimeInput"
            android:label="@string/MainMenu" >
        </activity>
        <activity
            android:name=".CoverPage"
            android:label="@string/MainMenu" >
        </activity>
        <activity
            android:name=".LoggedInActivity"
            android:label="LoggedIn" >
        </activity>
        <activity
            android:name=".RegisterAccountActivity"
            android:label="Register" >
        </activity>
        <activity
            android:name=".BaseActivity"
            android:label="Base" >
        </activity>
        <activity
            android:name=".AuthenticationActivity"
            android:label="Authentication" >
        </activity>
        <activity
            android:name=".NBHBaseActivity"
            android:label="Base" >
        </activity>
        <activity
            android:name=".CustomLoginActivity"
            android:label="Login" >
        </activity>
        <activity
            android:name=".Newsfeed"
            android:label="Login"
            android:windowSoftInputMode="adjustResize">
        </activity>
        <activity
        android:name=".NewsfeedInput"
        android:label="@string/MainMenu" >
    </activity>
        <activity
        android:name=".InfoWindowList"
        android:label="@string/MainMenu" >
    </activity>
        <activity
            android:name=".CrimeStats"
            android:label="@string/MainMenu" >
        </activity>
        <activity
        android:name=".GardaRegister"
        android:label="@string/MainMenu" >
    </activity>
        <activity
            android:name=".GardaLoginActivity"
            android:label="@string/MainMenu" >
        </activity>
        <activity
            android:name=".NeighborhoodRegister"
            android:label="@string/MainMenu" >
        </activity>
        <activity
            android:name=".NeighborhoodLogin"
            android:label="@string/MainMenu" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </>

</manifest>
3
  • Please edit your question and post your manifest file. It would appear that your android:name in <application> is pointing to an AuthenticationApplication class. Commented Mar 12, 2016 at 20:54
  • How can I add NBHAuthenticationApplication to the manifest? Commented Mar 12, 2016 at 21:01
  • I have added the manifest to the question Commented Mar 12, 2016 at 21:02

1 Answer 1

1

Replace:

android:name="AuthenticationApplication"

with:

android:name="NBHAuthenticationApplication"
Sign up to request clarification or add additional context in comments.

2 Comments

But I need AuthenticationApplication. Can I add another application?
@Cian: No. You can have only one Application subclass registered in the manifest. You need to combine your two Application subclasses into one, or have one inherit from the other.

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.