IllegalStateException异常:无活动 [英] IllegalStateException: No Activity

查看:127
本文介绍了IllegalStateException异常:无活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这对我的生活我不能想出一个很奇怪的问题。我有一个关于完成的应用程序。我已经开始测试它在模拟器不同Android版本和不同的屏幕尺寸/密度。一切正常,直到我到Android 3.1和3.2(蜂窝)。我得到一个 IllegalStateException异常:无活动每次应用程序启动。我开始还以为是我的应用程序,所以我通过堆栈跟踪去了,也没有在我的应用程序的任何方法或类的提及。所以我当时试图在我的应用程序支持所有Android版本,并且在每一个版本的工作,除了蜂窝。我Google蜂窝和 IllegalStateException异常:无活动,并没有发现任何东西。于是,我又看了看屏幕尺寸和实现了蜂窝的唯一皮肤WXGA。我检查了我所有的绘图资源,我用一个LDPI,MDPI,华电国际和xhdpi。但是为了以防万一我把我所有的应用程序需要到默认绘制文件夹中的可绘制,仍然有同样的问题。我用我所有的其他资源的默认文件夹,所以我知道这是不是原因。然后,我尝试了较小的屏幕尺寸和我惊讶的是它的工作。所以,我再测试了它在Android 4.1和使用1280×800和160的密度,以模仿WXGA。和它的工作就好了。因此,它具体到WXGA(1280×800 MDPI)和蜂窝。我调试,并通过我的code踩到它实际上成功地使它通过的onCreate()。我认为它实际上是通过去的onCreate()的两倍。我不重写 onResume()在这个活动。我在谷歌的土地花更多的时间,但我就是无法找到任何有关我所经历。万一它帮助这里是我的的onCreate()。如果任何人都可以对这个有何启示我会永远在你的债务。

  @覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main_activity);    mResources = getResources();
    支持mDialog =新ProgressDialog(本);    mUrl = mResources.getString(R.string.rate_url);
    mEmailSubject = mResources.getString(R.string.email_subject);
    mChoose = mResources.getString(R.string.email_choose);
    mSendTo = mResources.getString(R.string.email_send_to);
    mLoadingPlaces = mResources.getString(R.string.places_loading);
    mAmazonAppStore = mResources.getString(R.string.amazon_app);    mButton1 =(按钮)findViewById(R.id.tip_btn);
    mButton2 =(按钮)findViewById(R.id. preference);
    mButton3 =(按钮)findViewById(R.id.rate_btn);
    mButton4 =(按钮)findViewById(R.id.feedback_btn);    //加载字体和集的字体的每个按钮。
    字体TF = Typeface.createFromAsset(getAssets(),字体/ ArchitectsDaughter.ttf);    mButton1.setTypeface(TF);
    mButton2.setTypeface(TF);
    mButton3.setTypeface(TF);
    mButton4.setTypeface(TF);
}


解决方案

好吧也只是出于好奇,我回去,并试图再次。我本来打算安装它,并多次打开它,看看它是否起作用的任何时代。很让我惊讶它的工作时间EVERY !!!!!我一直在玩它了几分钟卸载并重新安装它和它的工作。这很奇怪,因为我知道我以前测试过的蜂窝,它在过去的工作。所以我不知道,如果它是也许只是在模拟器中一个小故障,但现在看来确定。我只希望我有这个配置的设备来测试它。因此,如果任何人有可能是什么造成这种任何意见或建议,我愿意寻找到每一个可以肯定的。

I am having a very odd problem that for the life of me I cant figure out. I have an app that is about finished. I have started testing it on different versions of Android and different screen sizes/densities in the emulator. Everything worked fine until I got to Android 3.1 and 3.2 (Honeycomb). I get an IllegalStateException: No Activity every time the app starts. I first thought it was my app so I went through the stack trace and there was no mention of any method or class in my app. So I then tried it on all Android versions supported by my app and it worked in every version except Honeycomb. I Googled Honeycomb and IllegalStateException: No Activity and didn't find anything. So I then looked at the screen size and realized the only skin for Honeycomb is WXGA. I checked all my drawables, I'm using one for ldpi, mdpi, hdpi, and xhdpi. But just in case I threw all the drawables my app needs into the default drawable folder and still had the same problem. I'm using the default folder for all my other resources so I know that isn't the cause. I then tried a smaller screen size and to my amazement it worked. So I then tested it on Android 4.1 and used 1280x800 and a density of 160 to mimic WXGA. And it worked just fine. So its specific to WXGA(1280x800 mdpi) and Honeycomb. I debugged and stepped through my code and it actually successfully makes it through onCreate(). I think it actually went through onCreate() twice. I am not overriding onResume() in this Activity. I spent more time in Google land but I just cant find anything related to what I am experiencing. Just in case it helps here is my onCreate(). If anybody can shed any light on this I will forever be in your debt.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    mResources = getResources();
    mDialog = new ProgressDialog(this);

    mUrl = mResources.getString(R.string.rate_url);
    mEmailSubject = mResources.getString(R.string.email_subject);
    mChoose = mResources.getString(R.string.email_choose);
    mSendTo = mResources.getString(R.string.email_send_to);
    mLoadingPlaces = mResources.getString(R.string.places_loading);
    mAmazonAppStore = mResources.getString(R.string.amazon_app);

    mButton1 = (Button) findViewById(R.id.tip_btn);
    mButton2 = (Button) findViewById(R.id.preference);
    mButton3 = (Button) findViewById(R.id.rate_btn);
    mButton4 = (Button) findViewById(R.id.feedback_btn);

    // Load the font and the set the font for each Button.
    Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/ArchitectsDaughter.ttf");

    mButton1.setTypeface(tf);
    mButton2.setTypeface(tf);
    mButton3.setTypeface(tf);
    mButton4.setTypeface(tf);
}

解决方案

Ok well just out of curiosity I went back and tried it again. I was gonna install it and open it multiple times to see if it worked any of the times. And to my amazement it worked EVERY time!!!!! I have been playing with it for a few minutes uninstalling and reinstalling it and its working. It was weird because I know I have tested it on Honeycomb before and it worked in the past. So I dont know if it was maybe just a glitch in the emulator but it seems ok now. I just wish I had a device with this configuration to test it on. So if anyone has any ideas or suggestions on what MIGHT have been causing this I am willing to look into each and every one to be sure.

这篇关于IllegalStateException异常:无活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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