Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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 Display Modes
  #1 (permalink)  
Old November 30th, 2009, 09:54 PM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 To Do List errors

I keep getting errors from eclipse that the arraylist cannot be resolved. Any help would be great.

Thanks,
Sam






Code:
package com.paad.todolist;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ListView;

public class ToDoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        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>();        aa = new ArrayAdapter<String>(this,
        							  android.R.layout.simple_list_item_1,
        							  todoItems);
        myListView.serAdapter(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;
        			}
        	}
        }
    }
}
Reply With Quote
  #2 (permalink)  
Old November 30th, 2009, 11:22 PM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to import the class. To do this manually, place the following line with the other import statements at the top of the file:
import java.util.ArrayList;

In Eclipse, there is an "Organize Imports" action that is useful for doing this automatically. Look under Source->Organize Imports. By default, the hotkey is Control/Command-Shift-O (windows/mac).

Hope that helps!
Reply With Quote
  #3 (permalink)  
Old November 30th, 2009, 11:53 PM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the tip, it helped to get rid of the errors on arraylist. I also get errors for the keylistener, keyevent, array, and array adapter. I've been trying to copy things word for word from the book and I am wondering why the tip you gave me isn't in the book. I'm new to all of this and am grateful for any help you can give me.

Last edited by louie2107; November 30th, 2009 at 11:54 PM. Reason: errors
Reply With Quote
  #4 (permalink)  
Old December 1st, 2009, 01:07 AM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I noticed those other imports were missing... Try using the "Organize Imports" action I mentioned. That should take care of all of the import errors you are getting.

I use "Organize Imports" all the time to keep autocomplete working as I reference external classes for the first time inside a class definition.
Reply With Quote
  #5 (permalink)  
Old January 12th, 2010, 04:09 PM
Registered User
 
Join Date: Jan 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error:Attempt to include a core VM class in something other than a

When I try to test the first ToDoList example I keep receiving the above message:

"Error:Attempt to include a core VM class in something other than a
core library. "

The message also includes a paragraph of snide comments from whoever programmed the message -- not appreciated by those of us new to Android.

What does the message mean, and how do I fix this? Eclipse shows no errors in the code, so I'm wondering if there is something in the properties or organization of the project that is causing the problem. Does anyone here know?
Reply With Quote
  #6 (permalink)  
Old March 23rd, 2011, 08:56 AM
Registered User
 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default simple_list_item_1 cannot be resolved or is not a field

[SOLVED]

When trying to run/debug the program, I get "simple_list_item_1 cannot be resolved or is not a field".

I've imported the necessary packages and I have to agree with the error since my R.java somehow doesn't include a variable like 'simple_list_item_1'. Neither has this been mentioned in the example.

I'm left wondering how the program recognises the android simple_list_item_1 when there's no reference or import to it? (I've just started with android, coming from mobile 6.5 with C# and am trying to get a feel for the differences between the two.)

used imports:
Code:
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;
my R.java looks like this;
Code:
package mypackage.todolist;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int myEditText=0x7f050000;
        public static final int myListView=0x7f050001;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

note: EditText and ListView were added to main.xml. I've also already added the onKeyListener.

Anyone know what I'm missing?

EDIT:
It seems that the reference to R should've been Android.R. I was thinking too much and changed that which made the program go awry. Should be ok now, although I'm still getting a fatal error on startup in the emulator, but atleast this's been solved.

Regards,

Djanello.

Last edited by djanello; March 24th, 2011 at 06:04 AM. Reason: Problem solved.
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
Multi Select List Box Coding Errors... snoopy92211 VB Databases Basics 10 June 30th, 2004 08:33 AM
Beginning Java 2 v1.3 errors list? amarelo BOOK: Beginning Java 2 1 June 7th, 2004 07:24 PM
Beginning Java 2 v1.3 errors list? amarelo Wrox Book Feedback 1 June 7th, 2004 01:59 PM
Runtime Errors List SerranoG Access VBA 1 March 24th, 2004 06:59 PM
Mailing List app has more errors - Help drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 1 September 7th, 2003 10:14 PM



All times are GMT -4. The time now is 08:01 PM.


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