2013-03-30 91 views
-1

我正在用按鈕和EditText製作一個簡單的android應用程序。運行應用程序時遇到困難

在Eclipse中,我已經寫此activity_main.xml中的文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:orientation="horizontal" 
    > 

    <EditText android:id="@+id/edit_message" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="@string/edit_message" /> 

    <Button android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_send" /> 


</LinearLayout> 

和在string.xml文件,我已經寫以下

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <string name="app_name">v1</string> 
    <string name="edit_message">Enter a Message</string> 
    <string name="button_send">Send</string> 
    <string name="menu_settings">Settings</string> 
    <string name="title_activity_main">MainActivity</string> 

</resources> 

代碼本身沒有顯示任何錯誤,但是當我嘗試運行代碼時,它會拋出錯誤。

我該怎麼辦?

+0

當您遇到錯誤時,請學會閱讀logcat。沒有這些信息,你是盲目的,不知道你面臨的問題的本質。你需要在這裏發佈logcat讓人們來幫助你。 – Snicolas

+0

你可以發佈你的Logcat錯誤 –

回答

0

拋出什麼樣的錯誤?我不確定,但這裏

<Button android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_send" /> 

你不使用android:id。如果你沒有id按鈕,你不能在java代碼中使用它。

0

您需要指定您將在java代碼中使用的按鈕的ID。

<Button 
    android:id="@id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_send" />