Wrox Programmer Forums
|
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 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 March 3rd, 2009, 06:22 PM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default Chap 2 ToDoList - Stopped Unexpectedly

I hope I didn't miss something basic, but my first attempt to run the ToDoList in Chapter 2 results in: "Sorry! The application To Do List has stopped unexpectedly. Please try again.". I assume there's an exception somewhere, but I'm too much of a novice to diagnose it.

Code:
package com.paad.todolist;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.view.View.*;
import android.widget.*;

public class ToDoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        // 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
        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;
            }
        });
    }
}
 
Old March 4th, 2009, 01:14 PM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I actually found the reason for my program crashing. I had dropped the call to:

super.onCreate(icicle);

from my method since the book didn't include this in the source code. Although the Eclipse template creates this call, I took the book's code literally which might confuse some readers in this case.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4 - customizing ToDoList - ruled lines not working correctly gregking BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 1 April 3rd, 2009 09:44 AM
HttpWebRequest - The connection was closed unexpectedly herrbanan C# 2005 4 January 20th, 2009 03:59 AM
ASP WebMatrix closes unexpectedly asp_princess ASP.NET 1.0 and 1.1 Basics 0 June 28th, 2007 09:36 AM
Reporting Server down unexpectedly japjit Reporting Services 1 January 11th, 2007 12:47 AM
access unexpectedly quit message ithunter Access 0 December 1st, 2004 12:32 PM





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