Apps application forced to close when list is scrolled to the most bottom

currycrab

Newbie
hi,

i have got some problem that whenever i scroll down my list view to the most bottom it crashed and was being asked to forced close. below is my code. can anyone help me with it. cant figure it out what happen because there was no error called when running the program.

is there a limit to the number of items placed in it?

thousand thanks in advance


Code:
package com.Z;



import com.Z.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class modulestudied extends Activity {
    
    
    
    
    
    /** Called when the activity is first created. */
    ListView listView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.modulestudied);
        
        
        Button buttonHomeView = (Button)findViewById(R.id.buttonHomeView);

        buttonHomeView.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            Intent intent = new Intent(modulestudied.this, homeview.class);
            startActivity(intent);
          }

        });
        
        
       


        listView = (ListView) findViewById(R.id.lv_module);
        listView.setAdapter(new EfficientAdapter(this));
    }
    private static class EfficientAdapter extends BaseAdapter {
       private LayoutInflater mInflater;
 
       public EfficientAdapter(Context context) {
            mInflater = LayoutInflater.from(context);
        }     
        public int getCount() {
            return modulestudied2.code.length;
        }
 
        public Object getItem(int position) {
            return position;
        }
 
       public long getItemId(int position) {
            return position;
        }
 
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.two_col_row, null);
                holder = new ViewHolder();
               holder.text1 = (TextView) convertView
                        .findViewById(R.id.TextView01);
                holder.text2 = (TextView) convertView
                        .findViewById(R.id.TextView02);

                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
           }

            holder.text1.setText(modulestudied2.code[position]);
            holder.text2.setText(modulestudied2.modulename[position]);
 
            return convertView;
        }
 
        static class ViewHolder {
            TextView text1;
            TextView text2;
        }
        
        }
    
    

}
 

currycrab

Newbie
Thread starter
i tried lessen the number of items in the list and i didnt crash.

but when i increase the amount of items in the list and when i scrolled down it crash.

anyone encountered this problem??
 

alostpacket

Over Macho Grande?
No worries, you get used to reading logcat after awhile :D

This is the important part:
09-12 14:05:39.899: ERROR/AndroidRuntime(472): FATAL EXCEPTION: main09-12 14:05:39.899: ERROR/AndroidRuntime(472): java.lang.ArrayIndexOutOfBoundsException
09-12 14:05:39.899: ERROR/AndroidRuntime(472): at com.Z.year1$EfficientAdapter.getView(year1.java:63)


So on line 63 of the getView method, you are getting an ArrayIndexOutOfBounds Exception

See if you can figure out why, and I will post back later -- I have to run to the store. :)

Also, try and keep your posts here in the thread rather than on my visitor page :) I think we can help more people if we talk here :D
 

currycrab

Newbie
Thread starter
some error in this code?

Code:
package com.Z;



import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class year1 extends Activity {
	
	/** Called when the activity is first created. */
    ListView listView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.year1modulelist);
        listView = (ListView) findViewById(R.id.lv_module);
        listView.setAdapter(new EfficientAdapter(this));
    }
    private static class EfficientAdapter extends BaseAdapter {
       private LayoutInflater mInflater;
 
       public EfficientAdapter(Context context) {
            mInflater = LayoutInflater.from(context);
        }	 
        public int getCount() {
            return year1moduleslist.code.length;
        }
 
        public Object getItem(int position) {
            return position;
        }
 
       public long getItemId(int position) {
            return position;
        }
 
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.two_col_row, null);
                holder = new ViewHolder();
               holder.text1 = (TextView) convertView
                        .findViewById(R.id.TextView01);
                holder.text2 = (TextView) convertView
                        .findViewById(R.id.TextView02);

                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
           }

            holder.text1.setText(year1moduleslist.code[position]);
            holder.text2.setText(year1moduleslist.modulename[position]);
 
            return convertView;
        }
 
        static class ViewHolder {
            TextView text1;
            TextView text2;
        }
    }
}



:D
 

alostpacket

Over Macho Grande?
yes, but I'm not sure what


my guess is something to do with these lines:

holder.text1.setText(year1moduleslist.code[position]); holder.text2.setText(year1moduleslist.modulename[position]);
 
Top