【问题标题】:Android Apps not working in emulatorAndroid 应用无法在模拟器中运行
【发布时间】:2010-05-05 21:49:23
【问题描述】:

我的应用程序都不能在模拟器中运行。我正在运行 Ubuntu 9.10,每次尝试访问我的 UI 时,应用程序都会崩溃。我得到的只是“对不起!应用程序......意外停止”。对于每个应用程序都会发生这种情况。

package com.mohit.helloandroid;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class HelloAndroid extends TabActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources();     //Resource object to get drawables
        TabHost tabHost = getTabHost();     //The activity tabhost
        TabHost.TabSpec spec;           //Reusable tab spec 
        Intent intent;

        intent = new Intent().setClass(this, HelloAndroid.class);

        spec = tabHost.newTabSpec("artists").setIndicator("Artists", res
            .getDrawable(R.drawable.tab_artists))
                .setContent(intent);
        tabHost.addTab(spec);
    }
}

我不知道这段代码怎么会抛出这样的消息。

【问题讨论】:

  • 你能发布你从日志中得到的异常吗?
  • 也不例外。这就是我感到困惑的原因。
  • 你能发布你的布局 XML 和你的 androidManifest XML 吗?

标签: java android android-emulator


【解决方案1】:

你至少有一些奇怪的事情发生了,其中任何一个都可能导致炸弹。

首先你打过电话:

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

但是你已经继承了 TabActivity,当你调用 super.OnCreate 时它会设置自己的内容视图。鉴于您拥有的代码,我猜您的 R.layout.main 可能是空的。摆脱 setContentView 调用。

接下来调用:

intent = new Intent().setClass(this, HelloAndroid.class);

您尝试通过传入这个本身是 tabHost 的类来创建在选项卡中显示的意图,并且在调用其 onCreate 时将尝试再次执行所有操作。如果 android 让这种情况发生,您将刚刚创建了一个无限递归调用,并且在内存不足时会导致手机崩溃。更有可能的是,我认为 Android 会在某些异常情况下爆炸,或者操作系统只会破坏该过程。

开始更简单。在您的资源中创建几个基本视图以显示在您的选项卡中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 2017-05-18
    • 2015-05-06
    相关资源
    最近更新 更多