gpt4 book ai didi

java - Android错误: Syntax error on token "}",删除此 token

转载 作者:行者123 更新时间:2023-12-01 23:56:50 24 4
gpt4 key购买 nike

我有以下代码,但似乎无法弄清楚为什么会收到上述错误消息。我显然知道这意味着什么,但我检查了括号,它们对我来说似乎是正确的。我正在运行 ADT 21.1.0。到目前为止,我已经尝试过重新启动 Eclipse;重新启动我的电脑;并重建该项目。

package cct.mad.lab;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class WalkList extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// storing string resources into Array
String[] players = getResources().getStringArray(R.array.players);

// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, players));
}

protected void onListItemClick (ListView 1, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}

最佳答案

这几乎肯定是因为 onListItemClick 定义中定义的标识符无效。

onListItemClick 中的 ListView 标识符从 1 更改为其他内容(有效标识符)。

来自jls-3.8 :

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.

有关 Java 字母的更多信息:

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

关于java - Android错误: Syntax error on token "}",删除此 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15467291/

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