在活动启动时的Andr​​oid抛出ClassCastException [英] android classcastexception on activity startup

查看:144
本文介绍了在活动启动时的Andr​​oid抛出ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的一个简单的活动计划。 基本上类只是扩展了活动。 但是,当我启动我在我的类的构造一个ClassCastException。 我不甚至有一个构造函数的定义,所以它必须是在活动是父类的构造函数。

不幸的是,调试犯规给它试图投什么类的任何详细信息。

这里是堆栈跟踪:

 发[< 1>主](暂停(RuntimeException的除外))
    ActivityThread $ PackageInfo.makeApplication(布尔值,仪器仪表)线:649
    ActivityThread.handleBindApplication(ActivityThread $ AppBindData)线:4232
    ActivityThread.access $ 3000(ActivityThread,ActivityThread $ AppBindData)线:125
    ActivityThread $ H.handleMessage(消息)线:2071
    ActivityThread $ H(处理器).dispatchMessage(消息)线:99
    Looper.loop()线:123
    ActivityThread.main(字符串[])线:4627
    Method.invokeNative(对象,对象[],上课,下课[],类,整型,布尔)行:不可用[本地方法]
    Method.invoke(对象,对象...)线:521
    ZygoteInit $ MethodAndArgsCaller.run()线:868
    ZygoteInit.main(字符串[])线:626
    NativeStart.main(字符串[])行:不可用[本地方法]
 

当我看着这个RuntimeException的我得到:

detailMessage无法实例化应用com.test.MyApp:java.lang.ClassCastException:com.test.MyApp(ID = 830067694464)

只有code是

  com.test包;
进口android.app.Activity;
公共类MyApp的延伸活动{

}
 

解决方案
  1. 开启的Andr​​oidManifest.xml
  2. 找到标记应用程序
  3. 删除属性安卓名称(如果存在)
  4. 添加属性安卓名=android.app.Application

这是我做过什么,问题已经走了。

PS:在步骤4中使用自定义的应用程序类的名称,如果你有一个(这是可选)

i have a simple activity program in android. basically the class just extends Activity. But when i start it i get a ClassCastException in the constructor of my class. i dont even have a constructor defined, so it must be in the constructor of the superclass which is Activity.

unfortunately the debugger doesnt give any detailed information on what class it is trying to cast.

here is the stacktrace:

Thread [<1> main] (Suspended (exception RuntimeException))  
    ActivityThread$PackageInfo.makeApplication(boolean, Instrumentation) line: 649  
    ActivityThread.handleBindApplication(ActivityThread$AppBindData) line: 4232 
    ActivityThread.access$3000(ActivityThread, ActivityThread$AppBindData) line: 125    
    ActivityThread$H.handleMessage(Message) line: 2071  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4627    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]  

and when i look into this runtimeexception i get:

detailMessage "Unable to instantiate application com.test.MyApp: java.lang.ClassCastException: com.test.MyApp" (id=830067694464)

the only code is

package com.test;
import android.app.Activity;
public class MyApp extends Activity {

}

解决方案

  1. Open AndroidManifest.xml
  2. Find tag application
  3. Remove attribute android:name (if exists)
  4. Add attribute android:name="android.app.Application"

This is what I did and the problem had gone.

P.S: In Step 4 use your custom application class name if you have one (that's optional).

这篇关于在活动启动时的Andr​​oid抛出ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆