Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 25th, 2009, 05:57 PM
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
  #2 (permalink)  
Old May 26th, 2009, 10:32 AM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You have a typo in the XML definition of myListView. It should be:

Code:
android:id="@+id/myListView"
(get rid of the '=').

Jeff S.
Reply With Quote
The Following User Says Thank You to sierawsk For This Useful Post:
ik09 (May 26th, 2009)
  #3 (permalink)  
Old May 26th, 2009, 11:00 AM
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Many thanks Jeff. Correcting that typo cleared my errors in R.java. I still had errors in TodoList.java however. Removing
Code:
 import android.R
fixed that issue and now I am up and running.
Reply With Quote
  #4 (permalink)  
Old December 8th, 2009, 08:26 AM
Registered User
 
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am also facing the same problem, and ur correction did not work for me. Can someone help me fix this problem.
Thanks in advance!!!!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS glitch of main layout yevi BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 17 February 21st, 2010 04:37 PM
3 column layout acevision7 BOOK: Professional CSS: Cascading Style Sheets for Web Design 0 February 24th, 2008 11:13 PM
Datalist layout silverfox_1188 ASP.NET 1.0 and 1.1 Professional 2 May 13th, 2005 05:43 AM
layout adflynn Java GUI 0 November 9th, 2004 06:33 AM



All times are GMT -4. The time now is 06:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.