运行应用程序很困难

时间:2013-03-30 12:50:16

标签: android eclipse

我正在制作一个带有按钮和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>

这样的代码没有显示任何错误,但是当我尝试运行代码时,它会抛出错误。

我该怎么办?

2 个答案:

答案 0 :(得分:0)

抛出了什么样的错误?我不确定,但在这里

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

你不使用android:id。如果您没有id按钮,则无法在java代码中使用它。

答案 1 :(得分:0)

您需要指定将在java代码中使用的按钮的ID。

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