java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

阿拂 发布于 2014/10/24 14:27
阅读 5K+
收藏 0
http://download.csdn.net/detail/qq_15795541/8075691
加载中
0
kakakakaka
kakakakaka
数组越界错误,数组地址为0的地方没有值
0
阿拂
阿拂

引用来自“kakakakaka”的评论

数组越界错误,数组地址为0的地方没有值
/**
 * 
 */
package com.xxkjx.lt.mmmlicai;


import java.util.ArrayList;
import java.util.List;


import com.xxkjx.lt.mmmlicai.R;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils.TruncateAt;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;


/**
 * @author Administrator
 * 
 */
public class YuSuanActivity extends Activity {
private List<String> spendSubjectal = new ArrayList<String>();
static List<String> yusuanAmountal = new ArrayList<String>();
static List<String> yueAmountal = new ArrayList<String>();
private int index;
private double sum;
private double yuesum;
private double zongyue;
private double spendAmount;
private double zongSpendAmount=0;
private double singleYue;
TextView zongyusuanTv;
TextView zongyusuanTv2;
Dialog dialogCalculator;
private NumberDialog num1;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.yusuan_main);
num1 = new NumberDialog(YuSuanActivity.this);


ListView yusuanlv = (ListView) this.findViewById(R.id.ListView1);


// DBUtil.insertYusuan(0, 100, "yusuan");
// DBUtil.insertYusuan(0, 200, "yusuan");
// DBUtil.insertYusuan(0, 300, "yusuan");
// DBUtil.insertYusuan(0, 50, "yusuanyue");
// DBUtil.insertYusuan(1, 150, "yusuanyue");
spendSubjectal = DBUtil.getSubjects("spendsubject");// 获得所有支出科目列表
Log.i("cd", String.valueOf(spendSubjectal.size()));//获得所有支出科目个数
yusuanAmountal = DBUtil.getAmount("yusuan");// 得到各支出科目相应的预算值
Log.i("cd", String.valueOf(yusuanAmountal.size()));
yueAmountal = DBUtil.getAmount("yusuanyue");// 得到各支出科目相应的预算余额
Log.i("cd", String.valueOf(yueAmountal.size()));
setYuSuanAdapter(yusuanlv, spendSubjectal, yusuanAmountal, yueAmountal); // 设置内容适配器
sum = DBUtil.zongYusuan("yusuan");// 总预算值
zongyusuanTv = (TextView) this.findViewById(R.id.TextView2);

for (int i = 0; i < spendSubjectal.size(); i++) {
if (Double.parseDouble(yusuanAmountal.get(i)) != 0) {// 若支出科目相应的预算值不为0
zongSpendAmount += DBUtil.getYuAmountAllDetails(spendSubjectal
.get(i).toString());// 获得指定支出科目相应的总支出金额
}
}
yuesum = sum - zongSpendAmount;// 总的预算余额
zongyusuanTv2 = (TextView) this.findViewById(R.id.TextView3);
if (sum != 0)// 若设置了预算总额
{
zongyusuanTv.setText(sum + "");//设置总预算额
zongyusuanTv2.setText("余额:  " + yuesum);//设置总预算余额
} else {//未设置预算总额
zongyusuanTv.setText("");//总预算额为空
zongyusuanTv2.setText("预算未设置");//设置总预算额的内容
}
ProgressBar pb = (ProgressBar) this.findViewById(R.id.progress_horizontal);
pb.setMax(100);//设置ProgerssBar的最大值
if (sum != 0) {
pb.setSecondaryProgress(100);
pb.setProgress((int) (100 - 100 * (yuesum / sum)));
} else {
pb.setSecondaryProgress(0);
pb.setProgress(0);
}
yusuanlv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
index = arg2;
num1.show();
num1.addJineListener(new NumberListener() {
@Override
public void doAction(String numstr) {
double yusuanamount = Double.parseDouble(numstr);
DBUtil.updateYusuan(index, yusuanamount, "yusuan"); // 更新预算表
spendSubjectal = DBUtil.getSubjects("spendsubject");
yusuanAmountal = DBUtil.getAmount("yusuan");
List<String[]> fl = DBUtil.getAmountAllDetails("zhichu"); // 预算科目,总额
for (int i = 0; i < fl.size(); i++) {
if ((fl.get(i) + "").equals(spendSubjectal
.get(index) + "")) {
spendAmount = DBUtil
.getYuAmountAllDetails((String) spendSubjectal
.get(index));
;
break;
} else
spendAmount = 0;
}
if (Double.parseDouble((String) yusuanAmountal
.get(index)) == 0) {
zongyue = 0;
} else
zongyue = Double
.parseDouble((String) yusuanAmountal
.get(index))
- spendAmount;
DBUtil.updateYusuan(index, zongyue, "yusuanyue");
spendSubjectal = DBUtil.getSubjects("spendsubject");
yusuanAmountal = DBUtil.getAmount("yusuan");
yueAmountal = DBUtil.getAmount("yusuanyue");
ListView yusuanlv = (ListView) findViewById(R.id.ListView1);
setYuSuanAdapter(yusuanlv, spendSubjectal,
yusuanAmountal, yueAmountal);
sum = DBUtil.zongYusuan("yusuan");
yuesum = DBUtil.zongYusuan("yusuanyue");
ProgressBar pb = (ProgressBar) YuSuanActivity.this
.findViewById(R.id.progress_horizontal);
pb.setMax(100);
pb.setSecondaryProgress(100);
if (sum != 0) {
pb.setProgress((int) (100 - 100 * (yuesum / sum)));
} else {
pb.setSecondaryProgress(0);
pb.setProgress(0);
zongyusuanTv.setText("");
zongyusuanTv2.setText("预算未设置");
}
zongyusuanTv2 = (TextView) YuSuanActivity.this
.findViewById(R.id.TextView3);
zongyusuanTv2.setText("余额:  " + yuesum);


zongyusuanTv = (TextView) YuSuanActivity.this
.findViewById(R.id.TextView2);
zongyusuanTv.setText(sum + "");
}


});
}
});
}
//setYuSuanAdapter(yusuanlv, spendSubjectal, yusuanAmountal, yueAmountal); // 设置内容适配器
public void setYuSuanAdapter(final ListView lv, final List<String> cl,final List<String> dl, final List<String> dl2) {
BaseAdapter ba = new BaseAdapter() {
@Override
public int getCount() {
// TODO Auto-generated method stub
//Log.i("len", String.valueOf(cl.size()));
return cl.size();


}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}


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


@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub

LinearLayout ll = new LinearLayout(YuSuanActivity.this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setPadding(5, 5, 5, 5);
// TextView 进度条
LinearLayout ll1 = new LinearLayout(YuSuanActivity.this);
ll1.setOrientation(LinearLayout.HORIZONTAL);
ll1.setPadding(5, 5, 5, 5);
// TextView
LinearLayout ll11 = new LinearLayout(YuSuanActivity.this);
ll11.setLayoutParams(new LayoutParams(150,android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
//用于显示支出科目
TextView tv = new TextView(YuSuanActivity.this);
tv.setText((CharSequence) cl.get(position));

Log.i("zckm", cl.get(position).toString());

tv.setTextSize(18);
tv.setTextColor(YuSuanActivity.this.getResources().getColor(R.color.black));
tv.setGravity(Gravity.LEFT);


// 余额
LinearLayout ll2 = new LinearLayout(YuSuanActivity.this);
ll2.setOrientation(LinearLayout.HORIZONTAL);
ll2.setPadding(5, 5, 5, 5);
// 总额
LinearLayout ll21 = new LinearLayout(YuSuanActivity.this);
ll21.setLayoutParams(new LayoutParams(300,android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
//用于显示支出科目的总预算
TextView tv2 = new TextView(YuSuanActivity.this);
Log.i("zys", String.valueOf(dl.get(position)));
if (Double.parseDouble((String) dl.get(position)) == 0)
tv2.setText("");
else
tv2.setText(String.valueOf(dl.get(position)));
tv2.setTextSize(14);
tv2.setTextColor(YuSuanActivity.this.getResources().getColor(R.color.black));
tv2.setGravity(Gravity.LEFT);
// 余额
LinearLayout ll22 = new LinearLayout(YuSuanActivity.this);
TextView tv3 = new TextView(YuSuanActivity.this);
tv3.setSingleLine(true);
tv3.setEllipsize(TruncateAt.END);
if (Double.parseDouble((String) dl.get(position)) == 0)
{ // zongyue=0;
tv3.setText("预算未设置");
}
else 
{
spendAmount = DBUtil.getYuAmountAllDetails(cl.get(position)+ "");//根据支出科目查询出总花费
Log.i("zcje", String.valueOf(spendAmount));
singleYue = Double.parseDouble((String) dl.get(position))- spendAmount;//求出余额
tv3.setText("余额:  " + singleYue);
Log.i("ye", String.valueOf(singleYue));
//DBUtil.updateYusuan(position, singleYue, "yusuanyue");

}
tv3.setTextSize(14);
tv3.setTextColor(YuSuanActivity.this.getResources().getColor(R.color.black));
// 进度条
LinearLayout ll12 = new LinearLayout(YuSuanActivity.this);
ProgressBar pb = new ProgressBar(YuSuanActivity.this,null,android.R.attr.progressBarStyleHorizontal);
pb.setLayoutParams(new LayoutParams(300, 30));
pb.setMax(100);
if (Double.parseDouble((String) dl.get(position)) != 0) {
pb.setSecondaryProgress(100);
if (singleYue > 0) {


double chengji = 100* (Double.parseDouble(dl2.get(position) + "")/ Double.parseDouble(dl.get(position) + ""));
pb.setProgress(100 - (int) chengji);
} else {
pb.setProgressDrawable(getResources().getDrawable(R.drawable.progress));
}

else 
{
pb.setSecondaryProgress(0);
pb.setProgress(0);
}
ll11.addView(tv);
    ll12.addView(pb);
ll21.addView(tv2);
ll22.addView(tv3);
ll1.addView(ll11);
ll1.addView(ll12);
ll2.addView(ll21);
ll2.addView(ll22);
ll.addView(ll1);
ll.addView(ll2);
return ll;
}
};
ba.notifyDataSetChanged();
lv.setAdapter(ba);
}
}

kakakakaka
kakakakaka
详细的报错信息,具体错误在几行
返回顶部
顶部