2011-09-28 148 views
2

我正在嘗試使用Eclipse運行Hello World教程代碼。我已經設置了AVD,但是當我嘗試運行代碼時,模擬器會加載到主屏幕,並且應用程序不會顯示。在控制檯中沒有顯示錯誤,並且logcat完全是空的(我也讓它運行了30分鐘)。Android應用程序不能在仿真器上運行

控制檯輸出:

[2011-09-28 18:00:31 - AndroidTest] ------------------------------ 
[2011-09-28 18:00:31 - AndroidTest] Android Launch! 
[2011-09-28 18:00:31 - AndroidTest] adb is running normally. 
[2011-09-28 18:00:31 - AndroidTest] Performing com.example.helloandroid.AndroidTest activity launch 
[2011-09-28 18:00:31 - AndroidTest] Automatic Target Mode: launching new emulator with compatible AVD 'myAVD' 
[2011-09-28 18:00:31 - AndroidTest] Launching a new emulator with Virtual Device 'myAVD' 

代碼:

package com.example.helloandroid; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class AndroidTest extends Activity 
{ 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     TextView tv = new TextView(this); 
     tv.setText("Hello World!"); 
     setContentView(tv); 
    } 
} 

我在Windows 7上運行64位。

謝謝。

+0

你有一個完整的清單文件? – cjk

+0

嘗試重新運行應用程序,一旦主屏幕可見(並且您解鎖了鍵鎖)。如果一個模擬器正在運行,你的應用程序將被部署到它而不是啓動一個新的。 – 2011-09-28 18:07:59

回答

0

我認爲你需要創建一個快速佈局,並將內容設置爲佈局。在你的/佈局文件夾 創建此home.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_layout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <TextView 
     android:id="@+id/my_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World" 
     android:textSize="24sp" 
     /> 
</LinearLayout> 

在的onCreate,爲此

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

這應該工作,

後來,你可以參考你的TextView並將其文本更改...

讓我們知道它是怎麼回事。

-serkan

0

解鎖模擬器和重新部署應用到它。

相關問題