views:

47

answers:

2

Good evening everyone! I am working on learning some java and I have made it to the notepad tutorial and when I go to run it on the emulator, I am getting a few errors, and I'm hoping someone here may be able to help.

package com.a8a.todolist;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.view.View.OnClickListener;

public class ToDoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        //Inflat 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 ArayAdapter<String>(this, android.R.layout.simple_list_item_1,todoItems);**    *Multiple markers at this line    - ArayAdapter cannot be resolved to a type  - Line breakpoint:ToDoList [line: 27] - onCreate*
     (Bundle)
        //Bind the arary adapter to the listview.
        myListView.setAdapter(aa);

        **myEditText.setOnKeyListener(new OnKeyListener() {**  *OnKeyListener cannot be resolved to a type*
            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;
            }
        });
    }
}[/CODE]

The bolded text is whats getting the error and the italics are the error itself. Any help would be appreciated, if you are able to explain why the change needs to be made as well that would be much appreciated, so I can learn from my mistakes.

Thanks in advance!

+1  A: 

ArayAdapter -- did you mean ArrayAdapter? Spelling is probably one of the first things I check when I get an error about an unknown type (followed by imports).

I believe you're also missing an import for OnKeyListener (import android.view.View.OnKeyListener). If you don't import a class and try to use it, Java doesn't know what it is, so it tells you it doesn't recognize the type.

HTH

cubic1271
Thank you all for your responses. Yes I am using Eclipse, good guess :D So I finally managed to get rid of those errors, and have completely compiled the code and when it launches in the emulator, it forces close. I have zipped the workspace so maybe someone can grab it and load it to see if they are able to see why its bombing out?http://www.deckertdesigns.com/Android/Todo_List.zipany help again, would be greatly appreciated. I feel once over this hump I will have some better knowledge in troubleshooting, just wish the debugger was catching this...
Rob
A: 

two spelling issue:

import android.view.View.OnClickListener; needs to change to : import android.view.View.OnKeyListener;

ArayAdapter needs to change to ArrayAdapter

mohammad shamsi