Satyam
Satyam

Reputation: 1682

Resource file(.R) cannot be resolved in content view Layout

I m getting error at setcontentview, its not taking layout main.Resource file is doesn't created can anybody solve my problem.

here is my code for main screen.

SqlitetestActivity.java file

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);
}

}

my 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>

I have tried restarting eclipse.. this doest work. any able to solve this problem. please insist me.. thanks in adbvance

Upvotes: 2

Views: 872

Answers (2)

Ponmalar
Ponmalar

Reputation: 7031

Just take 2 steps and problem would be more likely to get solved:

Step 1: Clean your project by clicking Project -> Clean.

Step 2: Rebuild your project by clicking Project -> Build All.

Also make sure that your layout xml files are syntax error free and you don't have any image which has non-acceptable names (such as a "-" between image name).

Upvotes: 2

Barak
Barak

Reputation: 16393

Check to see if you are importing the correct R file.

If there is an import for android.R... delete it and clean your project.

Upvotes: 2

Related Questions