1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by currycrab, Sep 12, 2011.

  1. currycrab

    currycrab Newbie
    Thread Starter

    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 (Text):
    1. package com.Z;
    2.  
    3.  
    4.  
    5. import com.Z.R;
    6.  
    7. import android.app.Activity;
    8. import android.content.Context;
    9. import android.content.Intent;
    10. import android.os.Bundle;
    11. import android.view.LayoutInflater;
    12. import android.view.View;
    13. import android.view.ViewGroup;
    14. import android.view.Window;
    15. import android.widget.BaseAdapter;
    16. import android.widget.Button;
    17. import android.widget.ListView;
    18. import android.widget.TextView;
    19.  
    20. public class modulestudied extends Activity {
    21.    
    22.    
    23.    
    24.    
    25.    
    26.     /** Called when the activity is first created. */
    27.     ListView listView;
    28.     public void onCreate(Bundle savedInstanceState) {
    29.         super.onCreate(savedInstanceState);
    30.        
    31.         requestWindowFeature(Window.FEATURE_NO_TITLE);
    32.        
    33.         setContentView(R.layout.modulestudied);
    34.        
    35.        
    36.         Button buttonHomeView = (Button)findViewById(R.id.buttonHomeView);
    37.  
    38.         buttonHomeView.setOnClickListener(new View.OnClickListener() {
    39.  
    40.           @Override
    41.           public void onClick(View view) {
    42.             Intent intent = new Intent(modulestudied.this, homeview.class);
    43.             startActivity(intent);
    44.           }
    45.  
    46.         });
    47.        
    48.        
    49.        
    50.  
    51.  
    52.         listView = (ListView) findViewById(R.id.lv_module);
    53.         listView.setAdapter(new EfficientAdapter(this));
    54.     }
    55.     private static class EfficientAdapter extends BaseAdapter {
    56.        private LayoutInflater mInflater;
    57.  
    58.        public EfficientAdapter(Context context) {
    59.             mInflater = LayoutInflater.from(context);
    60.         }    
    61.         public int getCount() {
    62.             return modulestudied2.code.length;
    63.         }
    64.  
    65.         public Object getItem(int position) {
    66.             return position;
    67.         }
    68.  
    69.        public long getItemId(int position) {
    70.             return position;
    71.         }
    72.  
    73.         public View getView(int position, View convertView, ViewGroup parent) {
    74.             ViewHolder holder;
    75.             if (convertView == null) {
    76.                 convertView = mInflater.inflate(R.layout.two_col_row, null);
    77.                 holder = new ViewHolder();
    78.                holder.text1 = (TextView) convertView
    79.                         .findViewById(R.id.TextView01);
    80.                 holder.text2 = (TextView) convertView
    81.                         .findViewById(R.id.TextView02);
    82.  
    83.                 convertView.setTag(holder);
    84.             } else {
    85.                 holder = (ViewHolder) convertView.getTag();
    86.            }
    87.  
    88.             holder.text1.setText(modulestudied2.code[position]);
    89.             holder.text2.setText(modulestudied2.modulename[position]);
    90.  
    91.             return convertView;
    92.         }
    93.  
    94.         static class ViewHolder {
    95.             TextView text1;
    96.             TextView text2;
    97.         }
    98.        
    99.         }
    100.    
    101.    
    102.  
    103. }
    104.  
    105.  
     



    1. Download the Forums for Android™ app!


      Download

       
  2. currycrab

    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??
     
  3. alostpacket

    alostpacket Over Macho Grande?

    What is the error message that LogCat gives when it crashes?
     
  4. currycrab

    currycrab Newbie
    Thread Starter

    sorry my logcat is kinda long :(:(

    http://pastebin.com/xmyJnq4i
     
  5. alostpacket

    alostpacket Over Macho Grande?

    No worries, you get used to reading logcat after awhile :D

    This is the important part:

    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
     
  6. currycrab

    currycrab Newbie
    Thread Starter

    some error in this code?

    Code (Text):
    1.  
    2.  
    3. package com.Z;
    4.  
    5.  
    6.  
    7. import android.app.Activity;
    8. import android.content.Context;
    9. import android.os.Bundle;
    10. import android.view.LayoutInflater;
    11. import android.view.View;
    12. import android.view.ViewGroup;
    13. import android.view.Window;
    14. import android.widget.BaseAdapter;
    15. import android.widget.ListView;
    16. import android.widget.TextView;
    17.  
    18. public class year1 extends Activity {
    19.    
    20.     /** Called when the activity is first created. */
    21.     ListView listView;
    22.     public void onCreate(Bundle savedInstanceState) {
    23.         super.onCreate(savedInstanceState);
    24.        
    25.         requestWindowFeature(Window.FEATURE_NO_TITLE);
    26.        
    27.         setContentView(R.layout.year1modulelist);
    28.         listView = (ListView) findViewById(R.id.lv_module);
    29.         listView.setAdapter(new EfficientAdapter(this));
    30.     }
    31.     private static class EfficientAdapter extends BaseAdapter {
    32.        private LayoutInflater mInflater;
    33.  
    34.        public EfficientAdapter(Context context) {
    35.             mInflater = LayoutInflater.from(context);
    36.         }    
    37.         public int getCount() {
    38.             return year1moduleslist.code.length;
    39.         }
    40.  
    41.         public Object getItem(int position) {
    42.             return position;
    43.         }
    44.  
    45.        public long getItemId(int position) {
    46.             return position;
    47.         }
    48.  
    49.         public View getView(int position, View convertView, ViewGroup parent) {
    50.             ViewHolder holder;
    51.             if (convertView == null) {
    52.                 convertView = mInflater.inflate(R.layout.two_col_row, null);
    53.                 holder = new ViewHolder();
    54.                holder.text1 = (TextView) convertView
    55.                         .findViewById(R.id.TextView01);
    56.                 holder.text2 = (TextView) convertView
    57.                         .findViewById(R.id.TextView02);
    58.  
    59.                 convertView.setTag(holder);
    60.             } else {
    61.                 holder = (ViewHolder) convertView.getTag();
    62.            }
    63.  
    64.             holder.text1.setText(year1moduleslist.code[position]);
    65.             holder.text2.setText(year1moduleslist.modulename[position]);
    66.  
    67.             return convertView;
    68.         }
    69.  
    70.         static class ViewHolder {
    71.             TextView text1;
    72.             TextView text2;
    73.         }
    74.     }
    75. }
    76.  
    77.  
    78.  
    79. :D
     
  7. alostpacket

    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]);
     
    currycrab likes this.
Loading...
Similar Threads - application forced close
  1. dvestal278b
    Replies:
    3
    Views:
    91
  2. Anca98
    Replies:
    1
    Views:
    512
  3. TienDat
    Replies:
    0
    Views:
    327
  4. Jason Edwardes
    Replies:
    3
    Views:
    374
  5. Wanda Manrara
    Replies:
    3
    Views:
    433
  6. Anne7890
    Replies:
    1
    Views:
    298
  7. hk1337
    Replies:
    0
    Views:
    536
  8. genie77
    Replies:
    13
    Views:
    1,669
  9. Leyna
    Replies:
    4
    Views:
    965
  10. merthkm
    Replies:
    1
    Views:
    1,335

Share This Page

Loading...