com.example.helloandroid.R.id无法解析

And*_*Eve 2 android unit-testing

我按照Hello,Testing教程的说法.

但是,以下行产生"com.example.helloandroid.R.id无法解析"错误:

  mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);
Run Code Online (Sandbox Code Playgroud)

Eclipse令人惊讶地提出了2个快速修复:

  1. 在"R"类型中创建字段"id"
  2. 在'R'类型中创建常量'id'

你能帮我理解这些修正是什么意思吗?这些确实是正确的修复方法吗?(为什么教程也没有提供它们?)

sit*_*uee 6

在HelloAndroid项目中,HelloAndroid.java

 setContentView(R.layout.main);
Run Code Online (Sandbox Code Playgroud)

检查你的HelloAndroid项目,在"gen-> com.example.helloandroid-> R.java"中有如下代码:

public static final class id {
 public static final int textview=0x7f050000;
}
Run Code Online (Sandbox Code Playgroud)

如果不是,请检查"res-> layout-> main.xml".有"android:id ="@ + id/textview"如下?

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/textview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="@string/hello"/>
Run Code Online (Sandbox Code Playgroud)

检查这些项目,如果需要,修复HelloAndroid.java和/或main.xml.重建HelloAndroid项目,并重建HelloAndroidTest项目.