Android 获取BaseAdapter中的ArrayIndexBounds异常
我正在创建一个应用程序,其中它由一个listview组成,而不是包含可展开listview的listview。当我在可展开列表视图中选择一个项目时,我收到一个错误,如下所示:Android 获取BaseAdapter中的ArrayIndexBounds异常,android,listview,custom-adapter,Android,Listview,Custom Adapter,我正在创建一个应用程序,其中它由一个listview组成,而不是包含可展开listview的listview。当我在可展开列表视图中选择一个项目时,我收到一个错误,如下所示: E/JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.) java.lang.ArrayIndexOut
E/JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
适配器:
public class Daybooklist_adapter extends BaseAdapter {
Context context;
private Activity activity;
private LayoutInflater inflater;
private ArrayList<Daybooklist> daybooklists;
DatabaseHandler databaseHandler;
boolean isListScrolling;
public Daybooklist_adapter(Activity activity, ArrayList<Daybooklist> daybooklists) {
this.activity = activity;
this.daybooklists = daybooklists;
}
@Override
public int getCount() {
return daybooklists.size();
}
@Override
public Object getItem(int i) {
return daybooklists.get(i);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertview, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertview == null)
convertview = inflater.inflate(R.layout.model_daybook_listentry, null);
final TextView day_name = (TextView) convertview.findViewById(R.id.tv_daybook_name);
final TextView day_description = (TextView) convertview.findViewById(R.id.tv_daybook_description);
final TextView day_type = (TextView) convertview.findViewById(R.id.tv_daybook_type);
final TextView day_amount = (TextView) convertview.findViewById(R.id.tv_daybook_amount);
final TextView day_usertype = (TextView) convertview.findViewById(R.id.tv_usertype);
final TextView day_time = (TextView) convertview.findViewById(R.id.tv_daybook_time);
final ImageView day_check = (ImageView) convertview.findViewById(R.id.img_doneall);
final TextView daybook_location = (TextView) convertview.findViewById(R.id.tv_daybook_location);
databaseHandler = new DatabaseHandler(activity);
// getting movie data for the row
final Daybooklist m = daybooklists.get(position);
if (m.getUsertype() != null && !m.getUsertype().isEmpty()) {
if (m.getUsertype().startsWith("farmer") | m.getUsertype().startsWith("singleworker") | m.getUsertype().startsWith("groupworker") | m.getUsertype().startsWith("payvehicle")) {
if (m.getUsertype().startsWith("farmer")) {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
String locat = String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno()));
locat = locat.replaceAll("\\[", "").replaceAll("\\]", "");
Log.e("farmerlocation", locat);
daybook_location.setText(locat);
day_type.setText(m.getType());
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
day_amount.setText("\u20B9" + m.getExtraamt());
if (m.getAmountout().startsWith("0.0") | m.getAmountout().startsWith("0")) {
// day_amount.setTextColor(activity.getResources().getColor(R.color.green));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.INVISIBLE);
} else {
// day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.VISIBLE);
}
day_time.setText(m.getCtime());
} else {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
daybook_location.setText(m.getType());
day_type.setText(m.getType());
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
day_amount.setText("\u20B9" + m.getExtraamt());
if (m.getAmountout().startsWith("0.0") | m.getAmountout().startsWith("0")) {
// day_amount.setTextColor(activity.getResources().getColor(R.color.green));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.INVISIBLE);
} else {
// day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
Log.e("Amountout", m.getAmountout());
day_check.setVisibility(View.VISIBLE);
}
day_time.setText(m.getCtime());
}
} else if (m.getUsertype().startsWith("advancefarmer") | m.getUsertype().startsWith("workeradvance") | m.getUsertype().startsWith("kgroupadvance") | m.getUsertype().startsWith("otherexpense") | m.getUsertype().startsWith("vehicle")) {
if (m.getUsertype().startsWith("advancefarmer")) {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
day_type.setText(m.getType());
String locat = String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno()));
locat = locat.replaceAll("\\[", "").replaceAll("\\]", "");
Log.e("farmerlocation", locat);
daybook_location.setText(locat);
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
Log.e("amountout", m.getAmountout());
day_amount.setText("\u20B9" + m.getAmountout());
day_time.setText(m.getCtime());
} else {
day_name.setText(m.getName());
day_description.setText(m.getType());
day_type.setText(m.getType());
daybook_location.setText(m.getDescription());
if (m.getName() != null && m.getName().startsWith("no")) {
day_name.setText(" ");
} else if (m.getDescription() != null && m.getDescription().startsWith("no")) {
day_description.setText(" ");
}
Log.e("amountout", m.getAmountout());
day_amount.setText("\u20B9" + m.getAmountout());
day_time.setText(m.getCtime());
}
} else if (m.getUsertype().startsWith("buyer")) {
day_name.setText(m.getName());
day_description.setText(m.getDescription());
day_amount.setText("\u20B9" + m.getAmountin());
day_type.setText(" ");
day_time.setText(m.getCtime());
daybook_location.setText(m.getType());
}
if (m.getUsertype().startsWith("farmer")) {
day_usertype.setText("F");
day_usertype.setBackgroundResource(R.drawable.textview_farmer);
} else if (m.getUsertype().startsWith("advancefarmer")) {
day_usertype.setText("FA");
day_usertype.setBackgroundResource(R.drawable.textview_farmer);
} else if (m.getUsertype().startsWith("singleworker")) {
day_usertype.setText("W");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("workeradvance")) {
day_usertype.setText("WA");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("groupworker")) {
day_usertype.setText("G");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("kgroupadvance")) {
day_usertype.setText("GA");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("otherexpense")) {
day_usertype.setText("E");
day_usertype.setBackgroundResource(R.drawable.textview_otherexpense);
} else if (m.getUsertype().startsWith("vehicle")) {
day_usertype.setText("V");
day_usertype.setBackgroundResource(R.drawable.textview_vehicle);
} else if (m.getUsertype().startsWith("gsalary")) {
day_usertype.setText("GS");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("isalary")) {
day_usertype.setText("WS");
day_usertype.setBackgroundResource(R.drawable.textview_worker);
} else if (m.getUsertype().startsWith("payvehicle")) {
day_usertype.setText("VP");
day_usertype.setBackgroundResource(R.drawable.textview_vehicle);
} else if (m.getUsertype().startsWith("buyer")) {
day_usertype.setText("B");
day_usertype.setBackgroundResource(R.drawable.textview_buyer);
}
}
convertview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
if (!isListScrolling) {
view.setBackgroundColor(Color.LTGRAY);
if (m.getUsertype().startsWith("farmer") | m.getUsertype().startsWith("advancefarmer")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent a = new Intent(activity, FarmerLedgerView_Activity.class);
a.putExtra("farmername", name);
a.putExtra("farmermobno", mobno);
activity.startActivity(a);
} else if (m.getUsertype().startsWith("singleworker") | m.getUsertype().startsWith("workeradvance")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent c = new Intent(activity, WorkerLedger_Activity.class);
c.putExtra("workername", name);
c.putExtra("workermobno", mobno);
activity.startActivity(c);
} else if (m.getUsertype().startsWith("groupworker") | m.getUsertype().startsWith("kgroupadvance")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent g = new Intent(activity, GroupWorkerLedger_Activity.class);
g.putExtra("groupname", name);
g.putExtra("workermobno", mobno);
activity.startActivity(g);
} else if (m.getUsertype().startsWith("isalary")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent d = new Intent(activity, Worker_paymenthistory_Activity.class);
d.putExtra("workername", name);
d.putExtra("workermobno", mobno);
activity.startActivity(d);
} else if (m.getUsertype().startsWith("bsalary")) {
Intent aa = new Intent(activity, WorkerListActivity.class);
activity.startActivity(aa);
} else if (m.getUsertype().startsWith("vehicle") | m.getUsertype().startsWith("payvehicle")) {
Intent s = new Intent(activity, VehicleList_activity.class);
activity.startActivity(s);
} else if (m.getUsertype().startsWith("otherexpense")) {
Intent b = new Intent(activity, OtherExpenseList.class);
activity.startActivity(b);
} else if (m.getUsertype().startsWith("buyer")) {
String name = m.getName();
String mobno = m.getMobileno();
Intent buyer = new Intent(activity, BuyerLedgerViewActivity.class);
buyer.putExtra("buyername", name);
buyer.putExtra("buyermobno", mobno);
activity.startActivity(buyer);
}
}
break;
}
return true;
}
});
return convertview;
}
public void isScrolling(boolean isScroll) {
isListScrolling = isScroll;
Log.e("Innerscrollcheck", String.valueOf(isListScrolling));
}
public类Daybooklist\u适配器扩展了BaseAdapter{
语境;
私人活动;
私人充气机;
私人ArrayList日记账表;
DatabaseHandler DatabaseHandler;
布尔滚动;
公共Daybooklist_适配器(活动活动、ArrayList daybooklists){
这个。活动=活动;
this.daybooklists=daybooklists;
}
@凌驾
public int getCount(){
返回daybooklists.size();
}
@凌驾
公共对象getItem(int i){
返回daybooklists.get(i);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
如果(充气器==null)
充气器=(充气器)活动
.getSystemService(上下文布局\充气机\服务);
if(convertview==null)
convertview=充气机。充气(R.layout.model\u daybook\u listentry,null);
final TextView day_name=(TextView)convertview.findViewById(R.id.tv_daybook_name);
最终文本视图日期描述=(文本视图)convertview.findViewById(R.id.tv\u daybook\u描述);
final TextView day_type=(TextView)convertview.findViewById(R.id.tv_daybook_type);
最终文本视图日金额=(文本视图)convertview.findViewById(R.id.tv日簿金额);
最终文本视图日期\用户类型=(文本视图)convertview.findViewById(R.id.tv\用户类型);
最终文本视图日期时间=(文本视图)convertview.findViewById(R.id.tv\u daybook\u时间);
最终ImageView日检查=(ImageView)convertview.findViewById(R.id.img\u doneall);
最终文本视图daybook\u位置=(文本视图)convertview.findViewById(R.id.tv\u daybook\u位置);
databaseHandler=新的databaseHandler(活动);
//正在获取行的电影数据
最终Daybooklist m=daybooklists.get(位置);
如果(m.getUsertype()!=null&!m.getUsertype().isEmpty()){
如果(m.getUsertype().StartWith(“farmer”)| m.getUsertype().StartWith(“singleworker”)| m.getUsertype().StartWith(“groupworker”)| m.getUsertype().StartWith(“payvehicle”)){
if(m.getUsertype().startsWith(“farmer”)){
day_name.setText(m.getName());
day_description.setText(m.getDescription());
String locat=String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno());
locat=locat.replaceAll(“\\[”,”).replaceAll(“\\[”,”);
Log.e(“农场位置”,locat);
daybook_location.setText(locat);
day_type.setText(m.getType());
如果(m.getName()!=null&&m.getName().startsWith(“否”)){
day_name.setText(“”);
}else if(m.getDescription()!=null和&m.getDescription().startsWith(“no”)){
day_description.setText(“”);
}
day_amount.setText(“\u20B9”+m.getExtraamt());
如果(m.getAmountout().startsWith(“0.0”)| m.getAmountout().startsWith(“0”)){
//day_amount.setTextColor(activity.getResources().getColor(R.color.green));
Log.e(“Amountout”,m.getAmountout());
日检查设置可见性(视图不可见);
}否则{
//day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
Log.e(“Amountout”,m.getAmountout());
日检查设置可见性(视图可见);
}
day_time.setText(m.getCtime());
}否则{
day_name.setText(m.getName());
day_description.setText(m.getDescription());
daybook_location.setText(m.getType());
day_type.setText(m.getType());
如果(m.getName()!=null&&m.getName().startsWith(“否”)){
day_name.setText(“”);
}else if(m.getDescription()!=null和&m.getDescription().startsWith(“no”)){
day_description.setText(“”);
}
day_amount.setText(“\u20B9”+m.getExtraamt());
如果(m.getAmountout().startsWith(“0.0”)| m.getAmountout().startsWith(“0”)){
//day_amount.setTextColor(activity.getResources().getColor(R.color.green));
Log.e(“Amountout”,m.getAmountout());
日检查设置可见性(视图不可见);
}否则{
//day_amount.setTextColor(activity.getResources().getColor(R.color.album_title));
Log.e(“Amountout”,m.getAmountout());
日检查设置可见性(视图可见);
}
day_time.setText(m.getCtime());
}
}否则如果(m.getUsertype().StartWith(“advancefarmer”)| m.getUsertype().StartWith(“workeradvance”)| m.getUsertype().StartWith(“kgroupadvance”)| m.getUsertype().StartWith(“其他费用”)| m.getUsertype().StartWith(“车辆”)){
if(m.getUsertype().startsWith(“advancefarmer”)){
day_name.setText(m.getName());
day_description.setText(m.getDescription());
day_type.setText(m.getType());
String locat=String.valueOf(databaseHandler.getfarmerlocation(m.getMobileno());
locat=locat.replaceAll(“\\[”,”).replaceAll(“\\[”,”);
Log.e(“农场位置”,locat);
daybook_location.setText(locat);
如果(m.getName()!=null&&m.getName().startsWith(“否”)){
day_name.setText(“”);
}else if(m.getDescription()!=null和&m.getDescription().startsWith(“no”)){
day_description.setText(“”);
}