在编译应用程序时寻找2个错误的帮助

时间:2010-08-28 18:36:05

标签: android eclipse java

大家晚上好!我正在学习一些java,我已经把它带到了记事本教程,当我在模拟器上运行它时,我收到了一些错误,我希望这里有人可以提供帮助。

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]

粗体文本是获取错误,斜体是错误本身。任何帮助将不胜感激,如果你能够解释为什么需要进行更改,我将非常感激,所以我可以从我的错误中吸取教训。

提前致谢!

2 个答案:

答案 0 :(得分:1)

ArayAdapter - 您的意思是ArrayAdapter吗?当我收到有关未知类型的错误(后跟导入)时,拼写可能是我检查的第一件事。

我相信你也错过了OnKeyListener的导入(导入android.view.View.OnKeyListener)。如果你没有导入一个类并尝试使用它,Java就不知道它是什么,所以它告诉你它不能识别它。

HTH

答案 1 :(得分:0)

两个拼写问题:

import android.view.View.OnClickListener;需要更改为:import android.view.View.OnKeyListener;

ArayAdapter需要更改为ArrayAdapter