所以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();
}
}
答案 0 :(得分:2)
尝试将ListView的ID更改为@+id/android:list
答案 1 :(得分:0)
尝试将其命名为其他内容
如果它不起作用,请检查您是否已导入包的资源。