Android 助手身份证有问题
我正在使用AIDE(Android IDE)编写一个简单的Android应用程序。我给了我的一个布局元素一个ID,但是当我尝试使用Android 助手身份证有问题,android,aide-ide,Android,Aide Ide,我正在使用AIDE(Android IDE)编写一个简单的Android应用程序。我给了我的一个布局元素一个ID,但是当我尝试使用findViewById()访问该元素时,我收到一个错误,上面写着:“com.mycompany.mailscommunes.R的未知成员'ID'。我在AIDE之外没有看到这个错误 这是Java代码: package com.mycompany.mailscomunes; import android.app.*; import android.os.*; impo
findViewById()
访问该元素时,我收到一个错误,上面写着:“com.mycompany.mailscommunes.R的未知成员'ID'。我在AIDE之外没有看到这个错误
这是Java代码:
package com.mycompany.mailscomunes;
import android.app.*;
import android.os.*;
import android.content.Intent;
import android.provider.ContactsContract;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.one);
}
}
这是相关的XML:
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/one"/>
删除这些行:
import android.app.*;
import android.os.*;
您实际上是在导入整个Android框架,其中包括布局文件,其中包含ID。而且您没有包含自己的ID文件(称为“R.java”) 因此,删除这两行,并包括这一行:
import com.mycompany.mailscomunes.R;
活动xml的根目录应为布局类型
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Text"/>
</LinearLayout>
转到您的项目,删除生成文件夹并进行重建。我也遇到了同样的问题,问题已经解决了您可以预览布局吗?当您关闭键盘时,点击布局XML编辑器中显示的工具栏右侧的小横向图标。如果没有问题,它也会自动重建资源,并显示错误MainActivity
中的r最终应该得到解决,尽管这可能需要一点时间。@MikeM.非常感谢,我照你说的做了,我的程序也自行修复了。你介意解释一下原因吗?AIDE的基本应用程序模板没有在任何地方的参考资料中定义任何ID,也没有在示例布局中分配给视图
,因此没有