Can't cast to Application with getApplication method

烈酒焚心 提交于 2019-11-29 11:58:36
<application
    android:label="@string/app_name"
    android:icon="@drawable/one"
    android:name=".App" >

You need to specify in your manifest to use your custom Application.

Here is the complete AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.Radio_KPI"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-sdk android:minSdkVersion="8"/>
    <uses-sdk android:targetSdkVersion="14"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
    android:name=".App"
    android:label="@string/app_name"
    android:icon="@drawable/one">
        <activity android:name=".Activities.Main"
                  android:screenOrientation="portrait"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  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=".Activities.About"
                  android:screenOrientation="portrait"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  android:label="@string/app_name">
        </activity>
        <activity android:name=".Activities.SavedSongs"
                  android:screenOrientation="portrait"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  android:label="@string/savedSongs">
        </activity>
        <service
                android:name=".Services.MyService">
        </service>
    </application>
</manifest>

use this..

in Manifest.xml

<application
android:label="@string/app_name"
android:icon="@drawable/one"
android:name=".App" >

in Activity

App app = (App)getApplicationContext();

Update this

<application
        android:name=".App"
        android:icon="@drawable/ijoomer_luncher_icon"
        android:label="@string/app_name"
 >

Do you have your new application object (App) registered in the manifest application tag? See the following application tag snippet for solution.

<application
        android:name=".App" 
        android:icon="@drawable/launcher_logo"
        android:label="@string/app_name" ... >
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!