package com.itxinke.www;import java.util.LinkedList;import android.app.Application;public class WeatherApplication extends Application
{
private LinkedList<WeatherInfo> weatherInfos; public WeatherApplication()
{
super();
weatherInfos = new LinkedList<WeatherInfo>();
// TODO Auto-generated constructor stub
} public LinkedList<WeatherInfo> getWeatherInfos()
{
return weatherInfos;
} public void setWeatherInfos(LinkedList<WeatherInfo> weatherInfos)
{
this.weatherInfos = weatherInfos;
}
}
这里我定义了一个类,继承于 Application类,用以保存全局变量。(其中weatherInfo是我自己设计的类)当我使用的时候 我是这么用的:WeatherApplication app = (WeatherApplication) getApplication();
app.setWeatherInfos(weatherInfos);
为什么会出现转换异常啊!不应该啊! 05-08 04:21:01.559: ERROR/AndroidRuntime(582): java.lang.ClassCastException: android.app.Application
05-08 04:21:01.559: ERROR/AndroidRuntime(582):     at com.itxinke.www.SplashActivity$1.run(SplashActivity.java:113)(这里指向的语句是:WeatherApplication app = (WeatherApplication) getApplication();)

解决方案 »

  1.   

    AndroidManifest.xml中
    application标签是否添加了 android:name=".WeatherApplication"
      

  2.   

    试试WeatherApplication app = (WeatherApplication) getApplicationContext();
      

  3.   

    在manifest.xml文件中的application标签中增加name属性
    <application android:name="TestApplication" 
      

  4.   

    <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" 
            android:name=".WeatherApplication"></application>即可