Wrox Programmer Forums
|
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2011, 03:54 PM
Registered User
 
Join Date: Apr 2011
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

Could you post your ToDoList activity as well? Thanks.
 
Old July 19th, 2011, 03:27 PM
Registered User
 
Join Date: May 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@McRae

Code:
package com.paad.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;

public class ToDoList extends Activity {

  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate your view
    setContentView(R.layout.main);
      
    // Get references to UI widgets
    ListView myListView = (ListView)findViewById(R.id.myListView);
    final EditText myEditText = (EditText)findViewById(R.id.myEditText);
    
    // Create the array list of to do items
    final ArrayList<String> todoItems = new ArrayList<String>();
    // Create the array adapter to bind the array to the listview
    int resID = R.layout.todolist_item;
    final ArrayAdapter<String> aa = new ArrayAdapter<String>(this,resID,todoItems);
    // Bind the array adapter to the listview.
    myListView.setAdapter(aa);
    
    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)
            {
              todoItems.add(0, myEditText.getText().toString());
              aa.notifyDataSetChanged();
              myEditText.setText("");
              return true;
            }
          return false;
        }
      });
  }
}
 
Old July 21st, 2011, 08:28 PM
Registered User
 
Join Date: Apr 2011
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

That seems to be in order. Have you tried just downloading the code and running it?
 
Old July 22nd, 2011, 03:21 PM
Registered User
 
Join Date: May 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@McRae: I have done that too, but no success. I use eclipse and the android emulator it creates. Could that be the problem? Could it be related to the memory usage?
The error I see every time is Android app crashed unexpectedly. Force close.

I appreciate any suggestion you may have. Thanks.
 
Old September 9th, 2011, 10:55 PM
Registered User
 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Same Problem

Has anyone fixed this? I went through the same steps and am getting the same problem.
I wound up coping and pasting the code from the book too....

I worry that it may be because I only have options for 2.1-update and higher for my project and there is nothing else available for down load. If this code wont work on 2.2 and 2.3 however its not very useful.

Anyone solve this problem?

-=Daniel=-



Quote:
Originally Posted by Spiffy View Post
Hello everyone! I'm having a problem running the ToDo List app from chapter 2. I figured out that extra imports were needed, so I downloaded the code examples from the website and was eventually able to get my code to compile and then execute on the emulator. But as soon as it does, I get the "Sorry! The Application ToDo List (process com.todo.list) has stopped unexpectedly. Please try again." And then my only option is to force close.

I've tried running it several times, and then even resorted to copying and pasting the code from the example into my project to see if I had just made some error somewhere, but the result doesn't change. Here is the code in my source file:

Code:
package com.todo.list;

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;

public class todoList extends Activity {
	 /** Called when the activity is first created. */
	  public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);

	    // Inflate your view
	    setContentView(R.layout.main);
	      
	    // Get references to UI widgets
	    final ListView myListView = (ListView)findViewById(R.id.myListView);
	    final EditText myEditText = (EditText)findViewById(R.id.myEditText);
	    
	    // Create the array list of to do 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);
	    
	    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)
	            {
	              todoItems.add(0, myEditText.getText().toString());
	              aa.notifyDataSetChanged();
	              myEditText.setText("");
	              return true;
	            }
	          return false;
	        }
	      });
	  }
	}
I have tried creating the project over again and setting the minimum SDK version to 5, but still nothing changed. Does anyone have an idea as to why this error is occurring? Thank you for your time! :)

EDIT: I just completed the Chapter 4 compass example, and I got the same error when trying to run it. This leads me to believe it MUST be something I'm doing, probably in setting up my projects, but what could it be?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - Todo List error jerrod1225 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 1 July 15th, 2010 07:17 PM
Getting a force close CH8 last example for Where Am I? benbeezy BOOK: Professional Android 2 Application Development 2 June 17th, 2010 07:29 PM
Problems w/ Force Close on Todo List Chapter 2 ogre150 BOOK: Professional Android 2 Application Development 2 June 9th, 2010 04:02 PM
Ch 4 Todo List 2 - odd behavior EricTapia BOOK: Professional Android 2 Application Development 1 March 21st, 2010 03:22 AM
Ch 09 router app error pwhited39 BOOK: Beginning Ruby on Rails 0 January 24th, 2009 08:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.