所以 Eclipse 告诉我,我的应用程序由于 RuntimeException 而崩溃:“您的内容必须有一个 ListView,其 id 属性是 android.R.id.list”。事情是这样的。正如您在下面看到的,我确实有一个 ID 为列表的 ListView,尽管我希望将其命名为更具描述性的名称。这是 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();
}
}