不幸的是myApp已停止在模拟器中

时间:2013-11-28 22:25:13

标签: java android eclipse emulation

但是,当我尝试运行应用程序时,我的android项目在控制台中没有显示任何错误。它会打开我的第一页,但是单击按钮时不会打开下一页。 以下是我的代码:

    package com.example.nearestparks;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class Information extends Activity {

    ListView list;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information);
        list=(ListView) findViewById(R.id.listView);
        list.setAdapter(new TinuAdapter(this));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.information, menu);
        return true;
    }

}

class SingleRow
{
    String title;
    String description;
    int image;

    SingleRow(String title,String descriptions,int image)
    {
        this.title=title;
        this.description=description;
        this.image=image;
    }

}


class TinuAdapter extends BaseAdapter
{

    ArrayList<SingleRow> list;
    Context context;
    TinuAdapter(Context c)
    {
        context=c;
        list=new ArrayList<SingleRow>();
        Resources res=c.getResources();
        String [] titles=res.getStringArray(R.array.titles);
        String [] descriptions=res.getStringArray(R.array.descriptions);
        int[] images={R.drawable.icon_park};
        for(int i=0;i<5;i++)
        {
            list.add(new SingleRow (titles[i],descriptions[i],images[i]));
        }

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        // TODO Auto-generated method stub
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        // TODO Auto-generated method stub
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row =inflater.inflate(R.layout.single_row,viewGroup,false);

        TextView title=(TextView)row.findViewById(R.id.textView1);
        TextView description=(TextView) row.findViewById(R.id.textView2);
        ImageView image =(ImageView) row.findViewById(R.id.imageView1);

        SingleRow temp = list.get(i);

        title.setText(temp.title);
        description.setText(temp.description);
        image.setImageResource(temp.image);




        return row;
    }




}

logcat上的错误显示java.lang.Array.OutOfBounds.Exception:length = 0;印出

任何帮助将不胜感激。提前谢谢!

1 个答案:

答案 0 :(得分:0)

int[] images={R.drawable.icon_park};

图像是一个项目数组,但在下面你循环5次

list.add(new SingleRow (titles[i],descriptions[i],images[i]));

因此,在第一次循环迭代后,图像[1]将失败。