【问题标题】:Compiler keeps saying error on my Id编译器一直在我的 ID 上说错误
【发布时间】:2014-03-11 15:01:03
【问题描述】:

在第3行R.id.edit_message编译器说edit_message cannot be resolve or is not a feild

public void sendMessage(View view) {
    Intent intent = new Intent(this, Display1MessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}

intent 应该跟在我的 xml 文件中的第 2 行“@+id/edit_message”之后

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

任何关于我如何解决这个问题的建议 plz

如果有帮助,这是我的清单和字符串

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
        android:name="com.example.myfirstapp.MainActivity"
        android:label="@string/app_name" >

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

    <activity
    android:name="com.example.myfirstapp.Display1MessageActivity"
    android:label="@string/title_activity_display1_message"
    android:parentActivityName="com.example.myfirstapp.MainActivity" >
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application></manifest><?xml version="1.0" encoding="utf-8"?>

<string name="app_name">MyFirstApp</string>
<string name="action_settings">Settings</string>
<string name="button_send">Send</string>
<string name="title_activity_main">MainActivity</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_display1_message">My Message</string>

【问题讨论】:

  • R 的导入是否正确?
  • 清理您的项目并重新构建它。
  • 删除 import android.R 如果你有它。
  • 在您的 Manifest 中,您过早关闭了“应用程序”:android:theme="@style/AppTheme" &gt; 但随后继续执行两行(其中一个是 label 属性的重复)...请删除第一行">" 和重复的 "android:label" 行(离开 ">")

标签: android


【解决方案1】:

转到项目菜单 -> 选择清理并按确定

它会完成的。

【讨论】:

  • 问题没有解决,还有其他建议吗?还是我应该提供我的完整代码?
  • 删除 import android.R 并按照我在答案中提到的那样做。希望它有效。基本上,这个错误是因为gen目录中没有R.java文件而引发的。
  • 感谢您的帮助,问题已解决。你介意告诉我为什么删除后 import android.R" 会起作用吗?是因为我在这个过程中错过了一些东西吗?
  • 希望这个问题对您有所帮助。 stackoverflow.com/questions/15309941/…
猜你喜欢
  • 2022-01-20
  • 2017-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多