我刚刚开始开发 Android 项目,但遇到了困难。我从开发者网站(http://developer.android.com/training/basics/firstapp/index.html)开始,我的问题从开始一个新的活动开始(http://developer.android.com/training/基础知识/firstapp/starting-activity.html)
该站点需要 Eclipse,我怀疑我错过了 Eclipse 幕后发生的一些事情,但我使用的是 IntelliJ IDEA。
在 DisplayMessageAcitivity.java 我收到以下错误:
cannot find symbol variable activity_display_message.
在 Eclipse 示例中,这是一个布局名称。
我包含了我第一次遇到问题时的代码,而不是我尝试修复时的代码。
显示消息活动:
public class DisplayMessageActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
}
}
安卓清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="13"/>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".DisplayMessageActivity"
android:label="My Message">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.MainActivity"/>
</activity>
</application>
</manifest>
R.java:
package com.example;
public final class R {
public static final class attr {
}
public static final class color {
public static final int testing_string_color=0x7f040000;
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int edit_message=0x7f060000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f050000;
public static final int button_send=0x7f050002;
public static final int edit_message=0x7f050001;
public static final int menu_settings=0x7f050003;
public static final int title_activity_main=0x7f050004;
}
}
主.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"/>
</LinearLayout>