2010-08-28 37 views
0

大家好!我正在学习一些java,并且已经将它写入了记事本教程,当我在仿真器上运行它时,出现了一些错误,我希望这里有人能够提供帮助。在编译应用程序时寻求2错误帮助

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] 

加粗的文本是什么得到的错误和斜体是错误本身。任何帮助,将不胜感激,如果你能够解释为什么需要改变,以及将不胜感激,所以我可以从我的错误中学习。

在此先感谢!

+0

您需要发布控制台的logcat日志,以便我们可以清楚地看到这些错误。 – Milan 2010-08-28 18:48:39

+1

你用什么工具编译这段代码?他们应该提醒你这些错误,并协助你在适当的进口 – 2010-08-28 18:50:28

+0

@Aaron:+1;好点子。看着“多重标记”一点,我猜罗布正在使用Eclipse; @Rob:如果我是对的,看看http://depth-first.com/articles/2008/01/11/my-favorite-eclipse-shortcut-quick-fix – cubic1271 2010-08-28 19:14:22

回答

0

两处拼写问题:

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

ArayAdapter需要改变到ArrayAdapter

1

ArayAdapter - 你的意思是ArrayAdapter?拼写检查可能是我在检查某个未知类型(后跟导入)时检查的第一件事情。

我相信你也缺少OnKeyListener的导入(导入android.view.View.OnKeyListener)。如果您不导入类并尝试使用它,则Java不知道它是什么,所以它会告诉您它无法识别类型。

HTH

+0

谢谢大家的回应。是的,我正在使用Eclipse,很好的猜测:D所以我最终设法摆脱了这些错误,并完全编译了代码,并且在模拟器中启动时,它强制关闭。我已经压缩了工作空间,所以也许有人可以抓住它并加载它看看他们是否能够看到为什么它被炸毁? http://www.deckertdesigns.com/Android/Todo_List.zip 任何帮助再次,将不胜感激。我感觉有一次在这个驼峰,我会有一些更好的故障排除知识,只希望调试器捕捉到这... – Rob 2010-08-28 19:38:12