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();)
{
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();)
解决方案 »
- 关于android中WebView显示的问题!!!
- 为什么我到android源码编译出来,没有system,img。。只有data和ramdisk.img
- 关于android的button点击一次没有反应
- android的WebView刷开谷歌百度地图的问题
- android模拟器局域网设置的问题
- 怎么实现 系统自带闹钟功能
- android大牛高焕堂最新力作-android架构师之路
- 关于android的activity的启动模式
- 谁能给讲讲Node.JS怎么跟Android配合开发
- NestedScrollView 嵌套 WebView出现的网页展示不全的问题
- 如何判断栈里是否存在一个activity??大牛来帮我啊
- 关于 滑动的引导界面
application标签是否添加了 android:name=".WeatherApplication"
<application android:name="TestApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".WeatherApplication"></application>即可