gpt4 book ai didi

java - Eclipse 声称我没有名为 R.id.list 的 ListView

转载 作者:行者123 更新时间:2023-11-29 21:36:56 25 4
gpt4 key购买 nike

所以 Eclipse 告诉我我的应用程序由于 RuntimeException 而崩溃:“您的内容必须有一个 ListView,其 id 属性是 android.R.id.list”。事情是这样的。正如您在下面看到的,我确实有一个 ListView,其 id 为 list,尽管我希望将其命名为更具描述性的名称。这是 activity_events.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#e5e5e5">

<ListView
android:id="@+id/list"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@null"
android:dividerHeight="0dp">

</ListView>

</LinearLayout>

<ProgressBar
android:id="@+id/eventsProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true" />

</RelativeLayout>

我在这里要疯了吗?我已经通过 onCreate 方法包含了所有内容,因为那是它崩溃的地方,但是调试器和 LogCat 并没有比我到目前为止告诉您的更多帮助。这是 EventsActivity.java 文件。

package com.barjinx.barjinx;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

public class EventsActivity extends ListActivity {

public static final int MAX_NUMBER_OF_ITEMS = 100;
public static final String TAG = EventsActivity.class.getSimpleName();
protected JSONObject mBarJinxData;
protected ProgressBar mProgressBar;

private final String KEY_BAR_NAME = "bar name"; //Key for eventual bar name to be plugged into Hashmap to populate list data
private final String KEY_GAME_SIDES = "game sides"; //Key for eventual game teams and their relationship to each other to be plugged into Hashmap to populate list data

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_events);

mProgressBar = (ProgressBar) findViewById(R.id.eventsProgressBar);
ListView list = new ListView(this);

if(isNetworkAvailable()) {
mProgressBar.setVisibility(View.VISIBLE);
GetEventsDataTask getEventsDataTask = new GetEventsDataTask();
getEventsDataTask.execute();
}
else {

Toast.makeText(this, R.string.network_unavailable , Toast.LENGTH_LONG).show();
}
}

最佳答案

尝试将 ListView 的 id 更改为 @+id/android:list

关于java - Eclipse 声称我没有名为 R.id.list 的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18222377/

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