Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:55:51+00:00 2026-06-06T23:55:51+00:00

I am getting ArrayIndexOutOfBoundsException when i try to delete a row from a listView

  • 0

I am getting ArrayIndexOutOfBoundsException when i try to delete a row from a listView in my android app. Following is the code:

 String[] items;
FileInputStream fis;
String FILENAME = "rundata";
String collected;
Context context = this;
int itemPosition;
FileOutputStream fos;
ArrayAdapter<String> adapter;
private static LayoutInflater inflater=null;

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


}

 @Override
protected void onResume(){
    super.onResume();
    inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    collected = null;

    try {
        fis = openFileInput(FILENAME);
        byte[] dataArray = new byte[fis.available()];
        while(fis.read(dataArray) != -1){
            System.out.println("in while");
            collected = new String(dataArray);
            if(collected.equals("")){
                System.out.println("break");
                break;
            }else{
                System.out.println("continue");
            }
        }
        fis.close();

        if(collected.contains("NEXTLINE")){
            System.out.println("in if next line");
            items = collected.split("NEXTLINE");
        }else{
            System.out.println("in else next line");
            items = new String[0];
        }


        System.out.println("items.length: "+items.length);

        adapter = new ArrayAdapter<String>(this, R.layout.historyrow, items){

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View vi = convertView;

                if (null == vi) {
                    vi = inflater.inflate(R.layout.historyrow, null);
                } else {
                    vi = convertView;
                }

                TextView text=(TextView)vi.findViewById(R.id.historyTxtTitle);

                JSONObject jObject;
                try {
                    jObject = new JSONObject(items[position]);
                    if(jObject.getString("activityMode").equals("mode1")){
                        text.setText("Mode 1");
                    }else if(jObject.getString("activityMode").equals("mode2")){
                        text.setText("Mode 2");
                    }else if(jObject.getString("activityMode").equals("mode3")){
                        text.setText("Mode 3");
                    }else if(jObject.getString("activityMode").equals("mode4")){
                        text.setText("Mode 4");
                    }else{
                        text.setText("ERROR");
                    }

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    System.out.println("++++++e: "+e);
                }

                return vi;
            }

        };

        setListAdapter(adapter);

and i get following error when i try to delete a row:

 06-28 11:15:10.593: E/AndroidRuntime(26639): FATAL EXCEPTION: main
 06-28 11:15:10.593: E/AndroidRuntime(26639): java.lang.ArrayIndexOutOfBoundsException
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at com.eplinovo.runnoandroid.HistoryViewActivity$1.getView(HistoryViewActivity.java:88)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.AbsListView.obtainView(AbsListView.java:1443)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.ListView.makeAndAddView(ListView.java:1793)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.ListView.fillDown(ListView.java:718)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.ListView.fillSpecific(ListView.java:1350)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.ListView.layoutChildren(ListView.java:1624)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.AbsListView.onLayout(AbsListView.java:1294)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.View.layout(View.java:7175)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.os.Handler.dispatchMessage(Handler.java:99)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.os.Looper.loop(Looper.java:130)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at android.app.ActivityThread.main(ActivityThread.java:3687)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at java.lang.reflect.Method.invokeNative(Native Method)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at java.lang.reflect.Method.invoke(Method.java:507)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
 06-28 11:15:10.593: E/AndroidRuntime(26639):   at dalvik.system.NativeStart.main(Native Method)

Can anybody please help me with that? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:55:52+00:00Added an answer on June 6, 2026 at 11:55 pm

    Because list adapter has a method called getCount – adapter assumes that items count is constant value, that returned by this method. After deleting a row you should call notifyDataSetChanged method of your adapter, so it’ll recalculate count of elements of your array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
OK so I am getting an ArrayIndexOutofBoundsException. I don't know why. Here's my code:
I have the following code in some app: int lowRange=50; int[] ageRangeIndividual = {6,
I'm working on a little server app with Java. So, I'm getting informations from
This is a continuation from: Recursive Fibonacci memoization . I keep getting an java.lang.ArrayIndexOutOfBoundsException
Getting my head around Android, I've sort of trouble understanding support for multiple devices.
I'm trying to add items to a JList asynchronously but I am regularly getting
Getting some zlib error in the middle of cloning big (4 GB) repo from
I am using iText to read from a PDF doc. I am getting an
I am getting Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 0 at com.ibm.icu.text.BreakDictionary.main(BreakDictionary.java:40) When I run/debug

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.