gpt4 book ai didi

android - 寻求有关编译应用程序时出现 2 个错误的帮助

转载 作者:行者123 更新时间:2023-12-01 16:02:08 26 4
gpt4 key购买 nike

大家晚上好!我正在学习一些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]

粗体文本是出现错误的原因,斜体是错误本身。如果您能够解释为什么需要进行更改,我们将不胜感激,这样我就可以从错误中吸取教训。

提前致谢!

最佳答案

ArayAdapter——您指的是ArrayAdapter吗?当我收到有关未知类型的错误(其次是导入)时,拼写可能是我首先检查的事情之一。

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

HTH

关于android - 寻求有关编译应用程序时出现 2 个错误的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3591959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com