2010-08-28 39 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