解决android java.lang.ClassCastException android.app.Application

定义类 DemoApp , 结果 Activity 调用始终报类错郁闷呀!

   class DemoApp extends Application{

   }

   下面的配置注意:

   

   <application android:icon="@drawable/icon"

             android:label="@string/app_name"

             android:debuggable="true"

            
android:name=".DemoApp">


  android:debuggable="true" 允许调试的意思







Firstly, you should create a new class that will behave as our global object, for example :


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

package

com.jameselsey.domain;

 

import

java.util.ArrayList;

import

java.util.List;

import

com.google.android.maps.GeoPoint;

import

android.app.Application;

 

/**

*
This is a global POJO that we attach data to which we

*
want to use across the application

*
@author James Elsey

*

*/

public

class

GlobalState
extends

Application

{

private

String testMe;

 

public

String getTestMe() {

return

testMe;

}

public

void

setTestMe(String testMe) {

this.testMe
= testMe;

}

}

The above class declares one String, with accessor methods. Soon we will see how this object will be available throughout the application. You can add anything you want onto this object, in my application I have a List of other domain classes that I wanted
to use elsewhere in my application.

Right, now that you have your global class defined, you need to specify this in your AndroidManifest file, otherwise the application won’t know where to find this class, and you will get a ClassNotFoundException

Locate your application tag, and add this into it :


1

android:name="com.jameselsey.domain.GlobalState"

It must reference your fully qualified global state class

Now you have it set, your ready to start putting data in, and pulling data out, use the following


1

2

3

4

5

6

7

//
Set values

GlobalState
gs = (GlobalState) getApplication();

gs.setTestMe("Some
String"
);</code>

 

//
Get values

GlobalState
gs = (GlobalState) getApplication();

String
s = gs.getTestMe();

And thats it! Off you go!

时间: 2024-08-02 08:13:44

解决android java.lang.ClassCastException android.app.Application的相关文章

集成EaseUI后运行报错:java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout

问题描述 具体报错信息06-23 09:26:58.154 7443-7443/com.*****.***** E/AndroidRuntime: FATAL EXCEPTION: main                                                                            Process: com.*****.*****, PID: 7443                                           

java.lang.NoSuchMethodError: android.support.v4.widget.SwipeRefreshLayout.setColorSchemeResources

问题描述 集成了easeui,刚开始没问题,后来加了初始化,并且登录退出的方法都加完之后,点开单聊的Fragment就报这个错误06-29 10:11:23.332 32183-32183/com.m1039.drive A/MobUncaughtExceptionHandler: android.support.v4.widget.SwipeRefreshLayout.setColorSchemeResources                                        

[Domino]“java.lang.ClassCastException:lotus.domino.cso.Item”异常解决办法

[Domino] "java.lang.ClassCastException:lotus.domino.cso.Item" 异常解决办法 编写者 日期 关键词 郑昀@ultrapower 2005-6 Java Domino RichTextItem   现象 通过Domino的Document.getFirstItem("Body")是可以获取当前邮件的Body字段,并试图直接转换为RichTextItem类型,从而访问该邮件的附件. 但是,有时候这个转换得到了下

java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.QuestionService

1 严重: Servlet /N002-1.0 threw load() exception 2 java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.QuestionService 3 at com.bbk.n002.servlet.CreateTaskQueueServlet.init(CreateTaskQueueServlet.java:28) 4 at ja

java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcesso

org.apache.jasper.JasperException: java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor         at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletW

jboss容器分离后启动时报出java.lang.ClassCastException

问题描述 jboss容器分离后启动时报出java.lang.ClassCastException 在做一个jboss容器分离的,已经新建了profile目录,而且deploy下我也确定只有一个ear发布包和一个数据源的xml配置.但是在启动的时候还是报出以下的问题 11:40:17,822 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=dcBackEnd-bet

java.lang.ClassCastException: Dispatch object expected

问题描述 运行项目出现异常:java.lang.ClassCastException:Dispatchobjectexpectedatcom.jacob.com.Dispatch.invokev(Dispatch.java:803)atcom.jacob.com.Dispatch.get(Dispatch.java:1153)atcom.lyang.governmentbill.utility.report.Java2Word.getTables(Java2Word.java:665)atcom

求高手解答 java.lang.ClassCastException: org.quartz.simpl.SimpleThreadPool

问题描述 使用quartz的时候,启动程序就抛出如下异常,不知道问题出在那,求解决...严重:Spring容器初始化过程中出现异常[wrzs_core]org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'getScheduling':Invocationofinitmethodfailed;nestedexceptionisorg.quartz.SchedulerException:T

急救: java.lang.ClassCastException: $Proxy2 cannot be cast to XXXX 错误

问题描述 我是个新手,这几天写了个小东西,刚开头就磕磕碰碰的,求哥哥大侠们能帮帮我.struts1.3+spring2.0+hibernate3报错信息:[com.jin.bbs.common.ActionExceptionHandler]-[ERROR] java.lang.ClassCastException: $Proxy2 cannot be cast to com.jin.bbs.user.UserManagerImpl at com.jin.bbs.user.presentation