そのため、Eclipse は、RuntimeException が原因でアプリがクラッシュしていることを教えてくれます。しかし、これが問題です。以下に示すように、もっとわかりやすい名前を付けたいと思っていますが、リストの 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();
}
}