2013-01-23 114 views
2

我已經用XML寫了一個應用程序,但我仍然沒有用java代碼編寫類。但模擬器可以顯示我的應用程序的名稱,然後它說「不幸的是,應用程序已停止。」我要爲這個問題做些什麼??!錯誤在Android模擬器上運行應用程序

這是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<Textview 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"/> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/TextView2"/> 
<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Button" 
    /> 

</LinearLayout> 
+2

,它通常會產生某種MainActivity類別,即使你沒有寫Java代碼。關於發生了什麼,應該有一些Logcat輸出,你可以發佈嗎? –

+0

@Chad Campbell:java.lang.classLoader.loadClass(ClassLoader.java.501)at android.view.LayoutInflater.onCreateView(LayoutInflater.java:552) .... –

+0

嗨@SetarehNaraghi。很好的問題 –

回答

0

必須在應用程序中至少有一個活動(Java類),這樣的manifest.xml能認識到並運行它。

+0

不客氣 –

+0

先生Ozturk你能給我你的電子郵件地址嗎?一個地址,我可以發送我的代碼給你,我真的有問題,我沒有人可以幫助我。 –

0

你必須使用一個活動以顯示這個XML:

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

正如你可以看到你的XML通過的setContentView方法調用。

這項活動必須在AndroidManifest.xml中當您創建的Android項目被宣佈與

<activity 
     android:name="YOURPACKAGE.ACTIVITY_NAME" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
+0

謝謝:) :) :) –

相關問題