【问题标题】:Resource file(.R) cannot be resolved in content view Layout资源文件 (.R) 无法在内容视图布局中解析
【发布时间】:2012-05-17 06:47:18
【问题描述】:

我在 setcontentview 遇到错误,它没有采用布局 main.Resource 文件没有创建任何人都可以解决我的问题。

这是我的主屏幕代码。

SqlitetestActivity.java 文件

public class SqlitetestActivity extends ListActivity {
protected EditText searchText;
protected SQLiteDatabase db;
protected Cursor cursor;  
protected ListAdapter adapter;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    searchText = (EditText) findViewById(R.id.searchText);
    db = (new DatabaseHelper(this)).getWritableDatabase();
}

public void onListItemClick(ListView parent, View view, int position, long id) {
    Intent intent = new Intent(this, StudentDetails.class);
    Cursor cursor = (Cursor) adapter.getItem(position);
    intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
    startActivity(intent);
}

public void search(View view) {
    // || is the concatenation operation in SQLite
    cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE firstName || ' ' || lastName LIKE ?", 
                    new String[]{"%" + searchText.getText().toString() + "%"});
    adapter = new SimpleCursorAdapter(
            this, 
            R.layout.employee_list_item, 
            cursor, 
            new String[] {"firstName", "lastName", "title"}, 
            new int[] {R.id.firstName, R.id.lastName, R.id.title});
    setListAdapter(adapter);
}

}

我的 main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:paddingTop="4dp">

<include android:id="@+id/search" layout="@layout/search" />

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/search"
    android:drawSelectorOnTop="false"/>

</RelativeLayout>

我已尝试重新启动 eclipse.. 这不起作用。任何能够解决这个问题的人。请坚持我.. 提前感谢

【问题讨论】:

  • 您遇到的错误可以发布您的错误日志,以便我们找出问题所在
  • 您是否尝试清理和构建项目?
  • m nt gettin error.. coz prgm doent run..
  • 尝试关闭项目并重新打开它。

标签: android android-layout android-intent android-widget


【解决方案1】:

只需采取 2 个步骤,问题就更有可能得到解决:

第 1 步:通过单击“项目”->“清理”清理您的项目。

第 2 步:通过单击 Project -> Build All 来重建您的项目。

还要确保您的布局 xml 文件没有语法错误,并且您没有任何名称不可接受的图像(例如图像名称之间的“-”)。

【讨论】:

    【解决方案2】:

    检查您是否正在导入正确的 R 文件。

    如果有 android.R 的导入...删除它并清理您的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      相关资源
      最近更新 更多