Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 2 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 Display Modes
  #1 (permalink)  
Old September 25th, 2010, 03:43 PM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Force Close error with CH.2 ToDo List App

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?

Last edited by Spiffy; September 25th, 2010 at 06:34 PM.
Reply With Quote
  #2 (permalink)  
Old September 28th, 2010, 05:16 AM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check the xml files of the main layout.
Do you have no "android:id" or double "android:id" in the "EditText" or "ListText" tags?
Are those ids the same in the xml and the main java source file?
Have you checked the "android:orientation" option in the "LinearLayout" tag?

Un saludo!
Reply With Quote
  #3 (permalink)  
Old November 8th, 2010, 05:45 PM
Registered User
 
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,
I have the same problem as you, I doubled check the code and the force close is still happening

here is my main.xml file

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">
	<EditView  
		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>
Reply With Quote
  #4 (permalink)  
Old January 17th, 2011, 10:03 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default update?

So what did you guys figure the problem is/was? I'm trying to figure it out right now myself.

Thanks!

Aaron
Reply With Quote
  #5 (permalink)  
Old April 23rd, 2011, 12:26 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ....hello?

This seems like it should be a pretty easy fix for anyone that's not new to this (which I am). I like the book, but there are quite a few failures in communication so far with things just not being explained fully. If anyone reads this and has a clue, please post.

Thanks!
Reply With Quote
  #6 (permalink)  
Old April 25th, 2011, 12:17 AM
Registered User
 
Join Date: Apr 2011
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

djeandroid: EditView in your main.xml file should be EditText.
Reply With Quote
The Following User Says Thank You to McRae For This Useful Post:
  #7 (permalink)  
Old July 14th, 2011, 10:27 PM
Registered User
 
Join Date: May 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am also trying to run the to do list in ch4 and I get the error that the app has unexpectedly closed. Like others my only option is force close. Any suggestion is appreciated.
Reply With Quote
  #8 (permalink)  
Old July 15th, 2011, 12:37 AM
Registered User
 
Join Date: Apr 2011
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

@mjafarin If you could post your main program code and your xml code that would be helpful.
Reply With Quote
  #9 (permalink)  
Old July 15th, 2011, 08:30 PM
Registered User
 
Join Date: May 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@McRae Here is my main.xml code.

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" />   
  <resources>
  	<string name="app_name">To Do List</string>
  	<color name="app_background">#FF0000FF</color>
  	<dimen name="default_border">5px</dimen>
  	<array name="string_array">
  		<item>Item 1</item>
  		<item>Item 2</item>
  		<item>Item 3</item>
  	</array>
  	<array name="integer_array">
  		<item>3</item>
  		<item>2</item>
  		<item>1</item>
  		</array>
  	  </resources>
  </LinearLayout>
Reply With Quote
  #10 (permalink)  
Old July 15th, 2011, 08:34 PM
Registered User
 
Join Date: May 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@McRae Attached are the codes for the xml files:

todolist_item.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<com.paad.todolist.TodoListItemView
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:padding="10dp"
	android:scrollbars="vertical"
	android:textColor="@color/notepad_text"
	android:fadingEdge="vertical"
/>
colors.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<color name="notepad_paper">#AAFFFF99</color>
	<color name="notepad_lines">#FF0000FF</color>
	<color name="notepad_margin">#90FF0000</color>
	<color name="notepad_text">#AA0000FF</color>
</resources>
dimens.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<dimen name="notepad_margin">30dp</dimen>
</resources>
string.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>
    <string name="cancel">Cancel</string>
</resources>
and styles.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="ToDoTheme" parent="@android:style/Theme.Black">
		<item name="android:textSize">12sp</item>
	</style>
</resources>

Last edited by mjafarin; July 15th, 2011 at 09:25 PM.
Reply With Quote
Reply


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



All times are GMT -4. The time now is 04:37 PM.


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