Wrox Programmer Forums
| 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 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 January 20th, 2012, 03:26 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default ToDo list in ch-2

Hi Wrox,

Your Book "Professional Android Application Development" is really very interesting..
and for starters you have explained clearly all the basics required to understand Android Development..
I'm very very new to Android Development..

I have some prob with ToDolist..
I am just posting code snippet here..
Can you plz help me out where i'm going wrong...

Code:
package com.todo;

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

public class ToDoList extends ListActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		setContentView(R.layout.main);

		ListView myListView = (ListView) findViewById(R.id.myListView);
		final EditText myEditText = (EditText) findViewById(R.id.myEditText);

		final ArrayList<String> todoItems = new ArrayList<String>();		
		final ArrayAdapter<String> aryAdapter;
		aryAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, todoItems);		
		myListView.setAdapter(aryAdapter);
		
		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());
						aryAdapter.notifyDataSetChanged();
						myEditText.setText("");
						return true;
					}
				return false;
			}
		});
	}
}
and xml file is as follows:

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/myEditText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint=""
        android:text="@string/txt_list" />

    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
when i execute this in emulator i get a msg as:
"Unexpectedly TO-Do has stopped"

and logcat shows as follows:
Code:
01-20 12:34:06.627: D/dalvikvm(610): Not late-enabling CheckJNI (already on)
01-20 12:34:11.697: D/AndroidRuntime(610): Shutting down VM
01-20 12:34:11.697: W/dalvikvm(610): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-20 12:34:11.818: E/AndroidRuntime(610): FATAL EXCEPTION: main
01-20 12:34:11.818: E/AndroidRuntime(610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.todo/com.todo.ToDoList}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.os.Looper.loop(Looper.java:137)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at java.lang.reflect.Method.invokeNative(Native Method)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at java.lang.reflect.Method.invoke(Method.java:511)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at dalvik.system.NativeStart.main(Native Method)
01-20 12:34:11.818: E/AndroidRuntime(610): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ListActivity.onContentChanged(ListActivity.java:243)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.Activity.setContentView(Activity.java:1835)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at com.todo.ToDoList.onCreate(ToDoList.java:22)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.Activity.performCreate(Activity.java:4465)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-20 12:34:11.818: E/AndroidRuntime(610): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-20 12:34:11.818: E/AndroidRuntime(610): 	... 11 more
01-20 12:34:15.877: I/Process(610): Sending signal. PID: 610 SIG: 9
so what might be the actual reason for this prob..??
Waiting for ur reply...

Regards,
Mounika




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 - Todo list, Enter ToDo Item disappearing cman123 BOOK: Beginning Building Mobile Application Development in the Cloud 6 April 7th, 2013 11:37 PM
Force Close error with CH.2 ToDo List App Spiffy BOOK: Professional Android 2 Application Development 14 September 9th, 2011 10:55 PM
Chapter 7 Todo List tinted BOOK: Professional Android 2 Application Development 2 August 26th, 2010 06:04 PM
Ch 4 Todo List 2 - odd behavior EricTapia BOOK: Professional Android 2 Application Development 1 March 21st, 2010 03:22 AM
ToDo List Problems - Chapter 4 wolverineik BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 0 February 28th, 2010 09:29 AM





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