1

RSSを読んで、結果をListViewに表示しようとしています。アプリが実行されてからクラッシュします。これは、リストアダプタ用に作成したクラス「theAdapter」が原因だと思います。

public class MainActivity extends Activity {
ArrayList<handler> PostList=new ArrayList<handler>(1000);
ListView list;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    list=(ListView)findViewById(R.layout.activity_main);
    new loading().execute("http://theurlfeed");
    }
class loading extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... params) {
        try {
            helper.parse(params[0]);
        } catch (IOException e) { e.printStackTrace();} 
              catch (XmlPullParserException e) {e.printStackTrace();}
        return null;
    }

    protected void onPostExecute(String s) {
        list.setAdapter(new theAdapter(MainActivity.this, PostList));
    }       
}}

public class handler {
String title="";
handler(String s){
    title=s;
}
String getTitle(){
    return title;
}}

私のxmlを読み取って解析するクラス

public class helper {

 public static ArrayList<handler> parse(String url) throws IOException, XmlPullParserException {
        final ArrayList<handler> results = new ArrayList<handler>(1000);
        String die=url;
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        URL input = new URL(die);
        xpp.setInput(input.openStream(), null);

        int eventType = xpp.getEventType();
        String currentTag = null;
        Integer id = null;
        String title = null;

            while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                currentTag = xpp.getName();
            } else if (eventType == XmlPullParser.TEXT) {
                if ("id".equals(currentTag)) {
                    id = Integer.valueOf(xpp.getText());
                }
                if ("title".equals(currentTag)) {
                    title = xpp.getText();
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if ("recipe".equals(xpp.getName())) {
                    results.add(new handler(title));
                }
            }
            eventType = xpp.next();
        }
        return results;
    }}

リストアダプタ

public class theAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<handler> data;
private static LayoutInflater inflater = null;
ViewHolder holder;

theAdapter(Activity a, ArrayList<handler> d) {
    activity = a;
    data = d;
    inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public static class ViewHolder {
    public TextView label;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.text, null);
        holder = new ViewHolder();
        holder.label = (TextView) vi.findViewById(R.id.title);
        vi.setTag(holder);
    } else
        holder = (ViewHolder) vi.getTag();
    holder.label.setText(data.get(position).getTitle());
    return vi;
}
public int getCount() {
    return 0;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}}

これがログです。

I / Process(1627):シグナルを送信しています。PID:1627 SIG:9

私は何が欠けていますか?

4

0 に答える 0