2010-05-05 156 views
0

我的應用程序都不在模擬器中工作。我運行Ubuntu 9.10,每次嘗試訪問我的用戶界面時,應用程序都會崩潰。我所得到的只是一個「對不起!應用程序意外停止」。對於每個應用程序,都會發生Android應用程序不能在模擬器中工作

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); 
    } 
} 

我不知道這段代碼如何可能拋出這樣的消息。

+0

你可以發佈你從日誌中獲得的異常嗎? – haseman 2010-05-05 22:35:42

+0

沒有例外。這就是我困惑的原因。 – 2010-05-05 23:17:14

+0

你能發佈你的佈局XML和你的androidManifest XML嗎? – Mark 2010-05-06 00:37:22

回答

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只會發生一些例外情況,或者操作系統將會破壞這個過程。

開始更簡單。在您的資源中創建幾個基本視圖以顯示在您的選項卡中。

相關問題