View Single Post
  #1 (permalink)  
Old May 25th, 2009, 05:57 PM
ik09 ik09 is offline
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chaoter 2 To Do List: R.layout.main cannot be resolved

Hello! I am just getting started with Eclipse and Android development, so I apologize if this is a simple fix. After working through the To Do List example, I am unable to run my application in the emulator because of three errors in ToDoList.java. I also have numerous errors in the R.java auto-generated file. I am running the current version of Eclipse, with Android 1.5r SDK and the current version of Java. I will post all of my code, and if anyone could read over it and let me know where my error is, I would greatly appreciate it!

src/org.example.TodoList/TodoList.java:

Code:
package org.example.TodoList;

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.R;

public class ToDoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Inflate your view
         setContentView(R.layout.main); [:confused:]  Eclipse error: R.layout.main cannot be resolved

         // Get references to UI widgets
         ListView myListView = (ListView)findViewById(R.id.myListView);  [:confused:] Error: R.id.myListView cannot be resolved
         final EditText myEditText = (EditText)findViewById(R.id.myEditText); [:(!]  Error: R.id.myEditText cannot be resolved

        
        //Create the array of to-do list items
        final ArrayList<String> todoItems = new ArrayList<String>();
        //Create the array adapter to bind the array to the listview
        final ArrayAdapter<String> aa;
        aa = new ArrayAdapter<String>(this,
                                        android.R.layout.simple_list_item_1,
                                        todoItems);
        //Bind the array adapter to the listView
        myListView.setAdapter(aa);
        
     // Add key listener to add the new todo item
         // when the middle D-pad button is pressed.
         myEditText.setOnKeyListener(new OnKeyListener() {
           public boolean onKey(View v, int keyCode, KeyEvent event) {
          if (event.getAction() == KeyEvent.ACTION_DOWN)
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
              // Add the new todo item, and clear the input text box
              todoItems.add(0, myEditText.getText().toString());
              myEditText.setText("");
              aa.notifyDataSetChanged();
              return true;
            }
          return false;
        }
      });
         
    }
    
  }
res/layout/main.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText
        android:id="@+id/myEditText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="New To Do Item" 
        />
        <ListView
            android:id="@+=id/myListView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
</LinearLayout>


res/values/strings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">To Do List</string>
    <string name="add_new">Add New Item</string>
      <string name="remove">Remove Item</string>
</resources>
Many thanks in advance! Thank you for the work you have done on this book Reto, it has been a joy to read so far!

Last edited by ik09; May 25th, 2009 at 06:02 PM.. Reason: spelling errors
Reply With Quote