我遇到一个很奇怪的问题,却一直无法解决。我有一个应用程序,几乎完成了。我在模拟器中开始测试不同版本的Android和不同的屏幕尺寸/密度。一切都很顺利,直到我遇到Android 3.1和3.2(Honeycomb)。每次应用程序启动时,我都会收到一个“
IllegalStateException: No Activity
”错误。我最初以为是我的应用程序出了问题,所以我查看了堆栈跟踪,但没有提到任何与我的应用程序相关的方法或类。因此,我尝试在我的应用程序支持的所有Android版本上运行它,并且在除Honeycomb之外的每个版本中都可以工作。我谷歌了Honeycomb和“IllegalStateException: No Activity
”,但没有找到任何有关的信息。所以我又看了一下屏幕尺寸,发现Honeycomb只有WXGA皮肤。我检查了所有的可绘制对象,使用了ldpi、mdpi、hdpi和xhdpi中的一个。但为了保险起见,我将所有应用程序需要的Drawable放入默认的drawable文件夹中,但仍然遇到了同样的问题。我对其他所有资源都使用了默认文件夹,所以我知道这不是原因。然后我尝试了一个更小的屏幕尺寸,惊讶地发现它可以工作。所以我在Android 4.1上进行了测试,并使用1280x800和密度160来模拟WXGA。结果它能够正常工作。所以这是特定于WXGA(1280x800 mdpi)和Honeycomb的问题。我调试并逐步执行我的代码,并且它实际上成功地通过了onCreate()
。我认为它实际上执行了两次onCreate()
。我没有在这个活动中覆盖onResume()
。我花了更多时间在Google上但是没有找到任何相关的信息。如果有人能够解决这个问题,我将永远感激不尽。以下是我的onCreate()
代码。@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);
}